Python Caesar密码发生错误

Python Caesar密码发生错误,python,encryption,Python,Encryption,因为我在计算机科学中的一项任务是通过使用关键字作为转换来创建凯撒密码,我一直在努力修复不断发生的错误,我也在努力修复它 import time exitReq = False while not exitReq: ############################################################################ print ('-' * 45) print('The Caesar Cipher') time

因为我在计算机科学中的一项任务是通过使用关键字作为转换来创建凯撒密码,我一直在努力修复不断发生的错误,我也在努力修复它

import time

exitReq = False
while not exitReq:
############################################################################    

    print ('-' * 45)
    print('The Caesar Cipher')
    time.sleep(1)
    print('Tom Payne 10B 2015')
    time.sleep(1)
    #Asks the user to enter all the information needed
    message = input('Please enter the phrase you want to encrypt: ')
    Encryption = ("Do you want to [E]ncrypt or [D]ecrypt") 
    shift_key = input('Please enter the keyword/phrase you would like to be your shift key : ')


     #Encyrpt
    def keyword_cipher(key, message):
        if Encryption == ("E"):
            if len(message) > len(key):
                while len(message) > len(key):
                    length_to_add = len(message) - len(key)
                    key = key + key[0:length_to_add]

            elif len(message) < len(key):
                while len(message) < len(key):
                    length_to_sub = len(key) - (len(key) - len(message))
                    key = key[0:length_to_sub]
        #Decrypt
        if Encryption == ("D"):
            if len(message) > len(key):
                while len(message) > len(key):
                    length_to_add = len(message) - len(key)
                    key = key - key[0:length_to_add]

        elif len(message) < len(key):
            while len(message) < len(key):
                length_to_sub = len(key) - (len(key) - len(message))
                key = key[0:length_to_sub]

        else:
            pass

        #shift the characters
        shifted_phrase = ''
        for i in range(len(message)):
            new_letter = (ord(key[i]) - 96) + (ord(message[i]) - 96) + 96
            if new_letter > 122:
                new_letter = chr(new_letter - 26)

            else:
                new_letter = chr(new_letter)


            shifted_phrase = shifted_phrase + new_letter
        return shifted_phrase


    #call it all to action
    result = keyword_cipher(shift_key, message)

    print ('Encrypted message:')
    print (result)

###############################################################################
    print ('=' * 45)
    time.sleep(1)
    exit = input('Would you like to exit: ')
    if (exit) == 'yes':
            exitReq = True
            print('Thank You. Goodbye')
            print ('-' * 45)


    if (exit) == 'no':
        exitReq = False
导入时间
exitReq=False
虽然不存在:
############################################################################    
打印('-'*45)
打印(“凯撒密码”)
时间。睡眠(1)
打印('Tom Payne 10B 2015')
时间。睡眠(1)
#要求用户输入所需的所有信息
message=input('请输入要加密的短语:')
加密=(“您想要[E]加密还是[D]加密”)
shift_key=input('请输入您希望成为shift key的关键字/短语:')
#百科全书
def关键字_密码(密钥、消息):
如果加密==(“E”):
如果len(消息)>len(键):
而len(消息)>len(键):
长度添加=len(消息)-len(键)
键=键+键[0:长度添加]
elif len(消息)len(键):
而len(消息)>len(键):
长度添加=len(消息)-len(键)
key=key-key[0:长度要添加]
elif len(消息)122:
新字母=chr(新字母-26)
其他:
新字母=chr(新字母)
移位短语=移位短语+新字母
返回移位短语
#行动起来
结果=关键字\u密码(shift\u键,消息)
打印('加密邮件:')
打印(结果)
###############################################################################
打印('='*45)
时间。睡眠(1)
exit=input('是否要退出:')
如果(退出)=“是”:
exitReq=True
打印('谢谢,再见')
打印('-'*45)
如果(退出)=“否”:
exitReq=False
每当我尝试运行代码时,就会出现以下错误:

    Traceback (most recent call last):

File "S:\Downloads\t2p.py", line 70, in <module>
    result = keyword_cipher(shift_key, message)
TypeError: keyword_cipher() missing 1 required positional argument: 'message'
回溯(最近一次呼叫最后一次):
文件“S:\Downloads\t2p.py”,第70行,在
结果=关键字\u密码(shift\u键,消息)
TypeError:keyword_cipher()缺少1个必需的位置参数:“message”

result=
之前,您是否可以打印消息在
while
循环之外定义函数。这应该会有帮助。你确定这是错误吗?顺便说一下,凯撒密码的密钥是[1..26]中的一个数字。如果您使用的是一个关键字,那么实际上您拥有的可能更像。
Encryption=(“您想[E]ncrypt还是[D]ecrypt”)
应该是
Encryption=input(“您想[E]ncrypt还是[D]ecrypt”)
(或者Python 2.x中的
raw_input()