python - Trying to encrypt string to ASCII -
this have not sure going wrong:
import sys message = input("enter message here:") key = input("enter key 1-100:") letter in message: char = ord(letter) if (char + key) < 32: encryptedchar = ((char - key) + 127) - 32 else: encryptedchar = (char - key) sys.stdout.write(chr(encryptedchar)) print(encryptedchar,end=" ")
i'm receiving error:
typeerror: unsupported operand type(s) +: 'int' , 'str')
key = int(input("enter key 1-100:"))
input
string, need cast integer.
after casting int code runs fine:
enter message here:foobar come in key 1-100:10 \92e101e101x88w87h104
python encryption
No comments:
Post a Comment