Question: I need to modify the python code bellow such that it can take a given text (plaintext), encrypt it with a given key, save the

I need to modify the python code bellow such that it can take a given text (plaintext), encrypt it with a given key, save the encrypted message in a new file(cyphertext), save the key in a new file, use the key to decrypt the message, and provide the decrypted message (back to the plaintext). from __future__import print function, unicode_literals from os import urandom def genkeyf(length): Generate a Key"" return urandom(length) def xor_strings(s, t): xor two strings together if isinstance(s, str): #text strings contain single characters return ""join(chr(ord(a) A ord(b))for a, b in zip(s,t) else #Python 3 bytes objects contain integer values in the range 0-255 return bytes([aAb for a, b in zip (s,t)) message This is a secret print (message: message) key genkey(len(message)) print (key:, key) cipherText xor_strings(message.encode(utf8),key) print (Cipher Text:, cipherText) print "Decrypted message:, xor strings(cipherText,key).decode(utf8) #verify if xor_strings(cipherText,key).decode(utf8)message: print (Encryption and Decryption correct') else print(Encryption and Decryption failed')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
