I have created a keyword encryption program in Python 3 but I have run into an error I don't know how to solve. The error is: TypeError: object of type 'builtin_function_or_method' has no len() It occurs on line 18 of my code.
ans = False
print(""" *****Hello. Welcome to the Vignère Cipher Encryption Program*****
***This program uses a keyword that is repeated until it
matches the same lenght of the message and then adds its
numerical value to the numerical value of the message and
outputs the encrypted message in alpha.
Please press:
E to Encrypt
D to Decrypt
or double tap enter to quit.
""")
ans=input("What would you like to do now???")
if ans == "E":
plaintext = str(input("Please enter a message to be encrypted: ")).upper
keyword = str(input("Please enter a keyword to be used to encrypt a message (alpha only): ")).upper
ciphered = " "
for i in range (len(plaintext)):
char = plaintext[i]
alphakeywordvalue = ord(keyword[i%len(keyword)]) - ord("A")+1
if char.isupper():
if cipher == "E" :
value = ord(char) + alphakeywordvalue
if value > ord("Z"):
value -= 26
print ("Your encrypted text is:", ciphered)
elif ans == "D":
plaintext = str(input("Please enter a message to be dencrypted: ")).upper
keyword = str(input("Please enter a keyword to be used to dencrypt a message (alpha only(make sure that it is the same keyword used to encrypt the message)): ")).upper
ciphered = " "
for i in range (len(plaintext)):
char = plaintext[i]
alphakeywordvalue = ord(keyword[i%len(keyword)]) - ord("A")+1
if char.isupper():
if cipher == "D" :
value = ord(char) - alphakeywordvalue
if value <ord("A"):
value += 26
ciphered += chr(value)
You forgot the parens from upper to actually call the method:
And on the next line:
In python3, input is already a string so calling str on it is redundant.