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

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....
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
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...
Python 3 Fix the code so the program reads the file and see if the bar...
Python 3 Fix the code so the program reads the file and see if the bar code was already inputted 3 times if so, it ishows a warning indicating that the item was already tested 3 times Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
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...
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 <...
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