没有密钥的Python Caesar密码程序

时间:2018-11-19 18:22:12

标签: python

在未指定任何移位的情况下,我希望对凯撒密码程序中的移位有所帮助。

我当前的程序:

def Decode():
    ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
    data = []
    string = input("Please enter the string you wish to decode.\n") 
    shift = int(input("Enter the key. (Number of shifts used when encoding original word.)\n"))
    for i in string:
        if i.strip() and i in ALPHABET: 
            data.append(ALPHABET[(ALPHABET.index(i) - shift) % 26]) 
        else:
            data.append(i)
    output = ''.join(data)
    return (output)

如何将这个程序转换为一个提示字符串进行解码的程序,并在文本中显示一个纯文本单词(解码后的字符串),并使用它们找出凯撒密码转换的密钥?

例如:如果编码字符串是:khoor zruog,而纯文本单词是:hello,则程序应计算出旋转为3,解码后的字符串为“ hello world”

必须在没有ord或char函数的情况下完成此操作。

0 个答案:

没有答案