简单 Python 凯撒密码
Simple Python Caesar Cipher
这是我的简单凯撒密码程序,但它运行不正常:
BASE = ord("a")
letter = input("Enter the message you want to encrypt:")
shift = int(input("The number you want to shift by: "))
lower_case = letter.lower
shift = BASE
new_strs = [""]
for character in lower_case:
new_strs.append(chr(BASE + ord(character) - shift) %26)
print ("".join(new_strs))
我想创建模数 26。换句话说,如果要移动的数字是 27,则程序循环回到字母表 a-z 的开头。当您在消息中留下 space 时,我也遇到了问题。提前谢谢你。
'''I added some parantheses and deleted the command shift = BASE '''
BASE = ord("a")
letter = input("Enter the message you want to encrypt:")
shift = int(input("The number you want to shift by: "))
# added ()
lower_case = letter.lower()
new_strs = [""]
for character in lower_case:
c = (ord(character) - BASE + shift) % 26
new_strs.append(chr(c + BASE))
print ("".join(new_strs))
这是我的简单凯撒密码程序,但它运行不正常:
BASE = ord("a")
letter = input("Enter the message you want to encrypt:")
shift = int(input("The number you want to shift by: "))
lower_case = letter.lower
shift = BASE
new_strs = [""]
for character in lower_case:
new_strs.append(chr(BASE + ord(character) - shift) %26)
print ("".join(new_strs))
我想创建模数 26。换句话说,如果要移动的数字是 27,则程序循环回到字母表 a-z 的开头。当您在消息中留下 space 时,我也遇到了问题。提前谢谢你。
'''I added some parantheses and deleted the command shift = BASE '''
BASE = ord("a")
letter = input("Enter the message you want to encrypt:")
shift = int(input("The number you want to shift by: "))
# added ()
lower_case = letter.lower()
new_strs = [""]
for character in lower_case:
c = (ord(character) - BASE + shift) % 26
new_strs.append(chr(c + BASE))
print ("".join(new_strs))