简单的Python Caesar密码

时间:2015-01-31 13:13:58

标签: python-3.x encryption module

这是我的简单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的开头。当你在邮件中留一个空格时,我也遇到了问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)


    '''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))