我用 python 制作了一个简单的脚本,它接受一个字符串,并通过将每个字母移动 1 到 10 之间的随机数来对其进行加密:
from random import randint
n = input('>>')
for i in n:
print(chr(ord(i) + randint(1,10)), end = '')
例如,我写“七”,它给我“yh~gx”。我想知道的是,当您编写字符串时是否有可能实现这种情况。例如,如果我想写“七”,它将显示“yh~gx”。我知道这在 C++ 中是可能的,但我不知道如何在 python 中做到这一点。
最佳答案
Python不太非常适合此类工作。我能找到的最佳解决方案仅适用于 Windows,并且没有办法退出程序,只能终止终端窗口(或者如果需要,您可以添加对某些字符的检查)。
import msvcrt
from random import randint
while True:
msvcrt.putch(chr((ord(msvcrt.getch()) + randint(1, 10)) % 128).encode('ascii'))
找到此解决方案here .
关于python - 在写入消息时对其进行加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45140493/