Python Forum

Full Version: TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'NoneType'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Please provide a runnable snippet that reproduces the problem, we shouldn't have to guess at the input that will do it. You should also include the full traceback, not just one line from it.