Question

In: Computer Science

Implement a Message Authentication Code program in either C/C++ or Python. 1. Accept a message as...

Implement a Message Authentication Code program in either C/C++ or Python.

1. Accept a message as keyboard input to your program.

2. Accept a secret key for the sender/recipient as keyboard input to your program.

3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85 + 67 = 378.

Concatenate the secret key of the sender/recipient (from step 2) and the message (from step 1) and compute the checksum of the concatenated string. For ASCII codes, refer to the following website:

http://www.asciitable.com

4. Accept a secret key for the attacker as keyboard input to your program.

5. The attacker modifies the message from step 1. The original message can be modified any way you want.

6. Concatenate the secret key of the attacker (from step 4) and the modified message (from step 5) and compute the checksum of the concatenated string.

7. Concatenate the secret key of the sender/recipient (from step 2) and the modified message (from step 5) and compute the checksum of the concatenated string.

8. Compare the checksum from step 7 and the checksum from step 6. See if they match or not.

9. Compare the checksum from step 3 and the checksum from step 6. See if they match or not.

NOTE: your program should have separate functions for the checksum and the message modification by the attacker.

Solutions

Expert Solution

#include <bits/stdc++.h>
using namespace std;

int checksum(string s)
{
   int ans=0;
   int n = s.size();
   char* arr;
   arr = &s[0];
    for (int i= 0; i<n; i++)
   { ans += (int)arr[i]; }
   return ans;
}
string modify(string s)
{
string temp;
cout<<"Enter the modified message"<<endl;
cin>>temp;
int n = temp.size();
s.replace(0,n,temp);
return s;
}
int main()
{
string s , se ,seh;//declaring the strings
cout<<"Enter the message"<<endl;
cin>>s;
cout<<"Enter the secret "<<endl;
cin>>se;

int secret = checksum(s+se);
cout<<"Enter the secret key for hacker"<<endl;
cin>>seh;
s = modify(s);//function to modify the string
int mod = checksum(s+seh);//finds the check sum of modified message + secret key from attacker
int mods = checksum(s+se);//finds the checksum of modified message + secret key from sender
if(mods == mod) cout<<"checksum of modified message+secret key from sender is equal to checksum of modified message+secret key from attacker"<<endl;
else cout<<"checksum of modified message+secret key from sender is not equal to checksum of modified message+secret key from attacker"<<endl;
if(secret == mod) cout<<"checksum of original message+secret key from sender is equal to checksum of modified message+secret key from attacker "<<endl;
else cout<<"checksum of original message+secret key from sender is not equal to checksum of modified message+secret key from attacker "<<endl;
return 0;
}


Related Solutions

implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1....
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1. Accept a message as keyboard input to your program. 2. Accept a secret key for the sender/recipient as keyboard input to your program. 3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85...
NC3A- 3.1 List three approaches to message authentication. 3.2 What is a message authentication code? 3.4...
NC3A- 3.1 List three approaches to message authentication. 3.2 What is a message authentication code? 3.4 What properties must a hash function have to be useful for message authentication? 3.5 In the context of a hash function, what is a compression function
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
DO IN C++ Secret Codes! Create a program that will accept a message from the user...
DO IN C++ Secret Codes! Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: - get the character you wish to encrypt - find the index of that character in the alphabet array - add the shift offset to the index - add the increment to the index - "wrap around" the new index so the result is between 0 and 29 - find the character at...
Complete the following in syntactically correct Python code. 1. The program should display a message indicating...
Complete the following in syntactically correct Python code. 1. The program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. Following are the guidelines: a. If the person is older than 1 year old or less, he or she is an infant. b. If the person is older than 1 year, but younger than 13, he or she is a child c. If the person is at least 13 years old,...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Can you convert this code (Python) to C++ def decrypt(message, key): decryptedText = "" for i...
Can you convert this code (Python) to C++ def decrypt(message, key): decryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k decryptedText += chr(xor) return decryptedText def encrypt(message, key): encryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k encryptedText += chr(xor) return encryptedText # main function userText = input("Enter text: ") userKey = str(input("Enter a key: ")) encryptedMessage = encrypt(userText, userKey)...
With C code Write a switch statement (not a complete program) which prints an appropriate message...
With C code Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages: If L is entered, output the message "Lakers" If C is entered, output the message "Clippers" If W is entered, output the message "Warriors" If any other character is entered, output the message "invalid code" Make sure to handle the case where the user enters in a small letter. That is, a capital or small...
Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test...
Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test scores and N student names (where 10 <= N <= 20). 2. Compute the sum and average of the scores (display these values). 3. Implement a function that determines the highest score (display this value). 4. Implement a function that determines the lowest score (display this value). 5. Implement a function that determines the letter grade of each score: 90-100 (A); 80 - 89...
C++ code Output Formatting. Design and implement a complete C++ program that reads a customer record...
C++ code Output Formatting. Design and implement a complete C++ program that reads a customer record from the user such as the record has 4 fields (pieces of information) as shown below: Account Number (integer) Customer full name (string) Customer email (string) Account Balance (double) The program is expected to print the record in the format shown below: Account Number :  0000000 Name                     :  full name Email                      :  customer email Balance                  :  000000.00$ For example, if the user enters the following record 1201077 Jonathan I. Maletic [email protected]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT