Python Forum
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'NoneType'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'NoneType'
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 758 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,013 Aug-24-2023, 05:14 PM
Last Post: snippsat
  Type Error: Unsupported Operand jhancock 2 1,197 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 5,266 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,330 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,175 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,884 May-07-2022, 08:07 AM
Last Post: menator01
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 3,013 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,415 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,068 Feb-09-2021, 05:40 PM
Last Post: soft

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020