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

Getting this error

print("Final message:",encryptDecrypt(cryptMode, startMessage, rotKey)) TypeError: encryptDecrypt() missing 1 required positional argument: 'Key'\

Cannot understand what Im doing wrong

kolobov666
  • 11
  • 2

1 Answers1

1

def encryptDecrypt(alphabet,mode,message,Key,final = ""): expects 4 arguments with a fifth optional.

You call it with only three: encryptDecrypt(cryptMode, startMessage, rotKey), missing the alphabet.

Corrected:

encryptDecrypt(alphabet, cryptMode, startMessage, rotKey)

clubby789
  • 2,543
  • 4
  • 16
  • 32
  • Now it says that print("Final message:",encryptDecrypt(alphabet, cryptMode, startMessage, rotKey)) File "Casesar.py", line 11, in encryptDecrypt final += alphabet[(alphabet.index(c) + Key)%(len(alphabet))] ValueError: substring not found – kolobov666 Feb 05 '20 at 11:45