Sep-06-2017, 04:49 PM
def encrypt(pk, plaintext): #Unpack the key into it's components key, n = pk #Convert each letter in the plaintext to numbers based on the character using a^b mod m cipher = [(ord(char) ** key) % n for char in plaintext] #Return the array of bytes return cipher def decrypt(pk, ciphertext): #Unpack the key into its components key, n = pk #Generate the plaintext based on the ciphertext and key using a^b mod m plain = [chr((char ** key) % n) for char in ciphertext] #Return the array of bytes as a string return plain