如何为Caeser密码完成此程序?

时间:2018-01-15 18:39:01

标签: python python-3.x encryption

我正在开发一个解密Caesar密码的程序。当我运行程序时,没有输出。提前谢谢!

这是我的代码

def test():
    value = input("Value here!") 
    with open ("cipher.*txt") as f:

        nice_strings = []
        for line in f:
            line = line.strip() 
            nice_str_chars = []

            for char in line:

                int_of_char = ord(char)

                int_of_char += value 
                nice_char = chr(int_of_char)

                nice_str_chars.append(nice_char)

            nice_str = ''.join(nice_str_chars)

            nice_strings.append(nice_str)

            print (line, '=>', nice_str, '\n')

        return nice_strings

1 个答案:

答案 0 :(得分:0)

我突然想到几个问题:

在您提供的代码中永远不会调用此函数。

文件名

似乎有问题

需要将输入值转换为整数,以便数学运算...

def test():
    ### convert the input to an integer
    value = int(input("Value here!"))

    ### presuming you want 'cipher.txt' versus 'cipher.*txt'
    with open ("cipher.txt") as f:      

        nice_strings = []
        for line in f:
            line = line.strip() 
            nice_str_chars = []

            for char in line:
                int_of_char = ord(char)
                int_of_char += value 
                nice_char = chr(int_of_char)
                nice_str_chars.append(nice_char)

            nice_str = ''.join(nice_str_chars)
            nice_strings.append(nice_str)
            print (line, '=>', nice_str, '\n')

        return nice_strings

### don't forget to call your function:

test()