Question

In: Computer Science

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 + 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 <iostream>

using namespace std;

long checksum(string str)
{

  long val = 0;
  for (char c : str)
    val += (int)c;

  return val;
}

string modify_message(string str)
{

  string modified = "";

  //increment each character by 1 but limited to ascii value of 125 -> }
  for (char c : str)
  {
    modified += min(126, c + 1);
  }

  return modified;
}

int main()
{
  //1. accept message
  string msg;
  cout << "Enter the sender message: ";
  cin >> msg;

  //2. accept secret
  string key;
  cout << "Enter the sender secret key: ";
  cin >> key;

  string final_msg = key + msg;

  //3. computing checksum
  long sender_checksum = checksum(final_msg);

  //4. accept attack secret
  string attack_key;
  cout << "Enter the attacker secret key: ";
  cin >> attack_key;

  //5. modify original message
  string modified_msg = modify_message(msg);

  //6. final attacker msg
  string final_attack_msg = attack_key + modified_msg;

  //6. compute checksum
  long attacker_checksum = checksum(final_attack_msg);

  //7. concatenate secret of sender and modified msg
  string final_sender_modified = key + modified_msg;

  //7. compute checksum
  long sender_modified_checksum = checksum(final_sender_modified);

  cout << "sender original checksum: " << sender_checksum << "\n";
  cout << "attacker checksum: " << attacker_checksum << "\n";
  cout << "sender modified checksum: " << sender_modified_checksum << "\n";

  //8. compare chekcsum from steps 7 and 6
  cout << "attacker checksum and sender modified checksum are ";
  if (attacker_checksum == sender_modified_checksum)
    cout << "equal";
  else
    cout << "not equal";
  cout << "\n\n";
  //9. compare checksums from steps 3 and 6
  cout << "original sender checksum and attacker checksum are ";
  if (sender_checksum == attacker_checksum)
    cout << "equal";
  else
    cout << "not equal";

  return 0;
}

output:

Using checksums can lead to same summation of characters allowing attacker to guess secret keys but they are mostly used to verify the integrity of data received.


Related Solutions

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,...
(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...
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;   ...
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...
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT