Sep-04-2019, 04:04 PM
I am pretty new to python, and I am trying to make a encrypter/decrypter, but my "if statement" is not working. Every time i run the program, it runs the first option("if action == "Krypter" or "krypter" :). I don't understand what I have done wrong here, please help.
alphabet = "abcdefghijklmnopqrstuvwxyzæøå" length = len(alphabet) action = input("Krypter eller Dekrypter: ") if action == "Krypter" or "krypter" : def encrypt(message,key) : def encode(letter, key) : pos = alphabet.find(letter) newpos = (pos + key) % length return alphabet[newpos] output = "" for character in message : if character in alphabet : output = output + encode(character, key) else: output = output + character print(output) encrypt(input("Krypter: "), int(input("Krypteringsnøkkel: "))) elif action == "Dekrypter" or "dekrypter" : def decrypt(secret_message, key) : def decode(letter, key) : pos = alphabet.find(letter) newpos = (pos - key) &length return alphabet[newpos] output = "" for character in secret_message : if character in alphabet: output = output + decode(character, key) else : output = output + character print(output) decrypt(input("Dekrypter: "), int(input("Dekrypteringsnøkkel: "))) else : exit()