缺少1个必需的位置参数:“密钥”加密

问题描述 投票:0回答:1
alphabet = ' abcdefghijklmnopqrstuvwxyz'
cryptMode = input("[E]ncrypt|[D]ecrypt: ").upper()
if cryptMode not in ['E','D']:
    print("Error: mode is not Found!"); raise SystemExit
startMessage = input("Write the message: ").upper()
try:rotKey = int(input("Write the key: "))
except ValueError: print("Only numbers!"); raise SystemExit
def encryptDecrypt(alphabet,mode,message,Key,final = ""):
    for c in message:
        if mode == 'E': 
            final += alphabet[(alphabet.index(c) + Key)%(len(alphabet))]
        else: 
            final += alphabet[(alphabet.index(c) - Key)%(len(alphabet))]
    return final
print("Final message:",encryptDecrypt(cryptMode, startMessage, rotKey))

收到此错误

print(“最终消息:”,encryptDecrypt(cryptMode,startMessage,rotKey))TypeError:encryptDecrypt()缺少1个必需的位置参数:“ Key” \

无法理解我在做什么错

python encryption caesar-cipher
1个回答
1
投票

[def encryptDecrypt(alphabet,mode,message,Key,final = ""):期望有四个参数,第五个可选参数。

您只用三个来称呼它:encryptDecrypt(cryptMode, startMessage, rotKey),缺少alphabet

更正:

encryptDecrypt(alphabet, cryptMode, startMessage, rotKey)

© www.soinside.com 2019 - 2024. All rights reserved.