Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在尝试将字符串加密为ASCII_Python_Encryption - Fatal编程技术网

Python 正在尝试将字符串加密为ASCII

Python 正在尝试将字符串加密为ASCII,python,encryption,Python,Encryption,这就是我不确定我会错在哪里的地方: import sys message = input("enter message here:") Key = input("enter a key from 1-100:") for Letter in message: Char = ord(Letter) if (Char + Key) < 32: encryptedChar = ((Char - Key) + 127) - 32

这就是我不确定我会错在哪里的地方:

import sys
message = input("enter message here:")
Key = input("enter a key from 1-100:")

for 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=" ")
input
是一个字符串,需要强制转换为整数

强制转换为int后,代码运行良好:

enter message here:foobar
enter a key from 1-100:10
\92e101e101X88W87h104

您正在尝试实现吗?假设您在python3中,问题是您正在尝试执行
Char
这是一个整数
+键
,这是一个字符串。(TypeError:不支持+:'int'和'str'的操作数类型)这是我得到的错误。对于Caesar密码,您必须遍历键中的字符。请在您的问题中编辑澄清。
Key = int(input("enter a key from 1-100:"))
enter message here:foobar
enter a key from 1-100:10
\92e101e101X88W87h104