Assignment# In Python

profileunique12
351_Assignment_2.py

# Name: Lalbabu Kumar Das # CWID: 50252733 # Assignment 2: Implementation of Message Authentication Code Program in Python # H() hash function to compute the checksum of the concatenated string( sender msg plus sender key) # This function has two parameters; input_msg and key def H(input_msg, key): concatenated_str = input_msg + key # Variable describing the concatenation of the secret key of the sender/recipient and the input msg checksum = 0 # checksum variable declared and initialized to zero for char in concatenated_str: # for loop to iterate the concatenated_str checksum += ord(char) # ord() = Python built in function to convert char to ASCII codes return checksum # Returns the checksum of concatenated string # msg_modification() function to modify the original msg by adding 5 to the original msg. # This function has one parameter as msg. def msg_modification(msg): change_msg = "" # change_msg variable declared here for char in msg: # for loop to iterate the msg change_msg += chr(ord(char) + 5) # Modification of the original message by adding 5 to the original value return change_msg # Returns the modified message # Driver program def main(): # Steps 1, 2 and 3 begins here print("----------Start of the steps 1, 2 and 3----------") # Prompt the user to enter the original message of sender/recipient # strip() is used to remove the spaces at the begining and at the end of the string original_msg = str(input("Please enter the original message of sender/recipient: ")).strip() # Prompt the user for the secret key of the sender/recipient # strip() is used to remove the spaces at the begining and at the end of the string secret_key1 = str(input("Please enter the secret key for the sender/recipient: ")).strip() # checksum calculation of the the original message and the secret key of the sender/recipient senderRecipientChecksum = H(original_msg, secret_key1) # Printing the sender/recipient checksum of original message and secret key print("Sender/Recipient checksum of original_msg and secret_key1: ", senderRecipientChecksum) # Steps 1, 2 and 3 ends here print("----------End of the steps 1, 2 and 3----------") # Steps 4, 5, 6 and 7 begins here print("\n----------Start of the steps 4, 5, 6 and 7----------") # Prompt the user to enter the Secret key for the attacker # strip() is used to remove the spaces at the begining and at the end of the string secret_key2 = str(input("Please enter the secret key for the attacker: ")).strip() # Attacker modifying the original message msg_modified_attacker = msg_modification(original_msg) # Printing the modified message done by attacker print("The modified version of original message is: ", msg_modified_attacker) # checksum calculation of the modified message and the secret ey of the attacker attackerChecksum = H(msg_modified_attacker, secret_key2) # Printing the checksum of the attacker modified message and attacker secret key print("Checksum of the concatenation of the modified message and attacker secret key: ", attackerChecksum) # checksum Calculation of the concatenation of the modified message and the secret key of the sender/recipient senderRecipientCheksum2 = H(msg_modified_attacker, secret_key1) # Printing the checksum of the concatenation of the modified message and the secret ky of the sender/recipient print("Checksum of the modified message and sender/recipient secret key: ", senderRecipientCheksum2) # Steps 4, 5, 6 and 7 ends here print("----------End of the steps 4, 5, 6 and 7----------") # Steps 8 and 9 begins here print("\n----------Start of the steps 8 and 9----------") # Checksum comparison between the sednderRecipientChecksum2(checksum of modified message and sender/recipient # secret key) and attackerChecksum senderRecipientChecksum2_compare_attackerCheksum = (attackerChecksum == senderRecipientCheksum2) # Printing the comparison result of checksum print("Sender/Recipient checksum for modified msg and attacker checksum for modified msg are matching or not: ", senderRecipientChecksum2_compare_attackerCheksum) # Checksum comparison between the sednderRecipientChecksum (checksum of original message and sender/recipient # secret key) and attackerChecksum senderRecipientChecksum1_compare_attackerChecksum = (senderRecipientChecksum == attackerChecksum) # Printing the comparison result of checksum print("Sender/Recipient checksum for orginal msg and attacker checksum for modified msg are matching or not: ", senderRecipientChecksum1_compare_attackerChecksum) # Steps 8 and 9 ends here print("----------End of the steps 8 and 9----------") main() # calling the main function