def displayMenu(): print("1. Encrypt New Message.") print("2. Decrypt Message.") print("3. Quit.") print("Enter Choice: ", end="") def encryptMessage(): # get plain text from user Plaintext = input("Enter New Message: ") valid = False # get key from user (iterate until the user has input a key that is long enough) while not valid: OneTimePad = input("Enter New Key: ") if len(OneTimePad) < len(Plaintext): print("Key is not long enough!") else: valid = True # apply bit-wise XOR ('^' in python) to each character of the plaintext and key # and build up the cipher text Ciphertext = "" for counter in range(0, len(Plaintext)): Ciphertext = Ciphertext + chr(ord(Plaintext[counter]) ^ ord(OneTimePad[counter])) print("Cipher text:", Ciphertext) # some of the characters may be non-printing, so output as binary to a binary file # (rather than a text file) # The key is text (was typed in by the user) so output as text to a text file f1 = open("Message.txt", "wb") f2 = open("Key.txt", "w") f1.write(bytes(Ciphertext, 'utf-8')) f2.write(OneTimePad) f1.close() f2.close() # add code to this procedure to decrypt the message that is in the message.txt file def decryptMessage(): pass # code starts running here choice = 0 while choice != 3: displayMenu() choice = int(input()) if choice == 1: encryptMessage() if choice == 2: decryptMessage()