In this example, you can see that I set plain_text
as a parameter to the encrypt
function and cipher_text
as a parameter to the decrypt
function. However, when I only use for example plain_text
in my encrypt
function, it does not work where as if I use both plain_text
and cipher_text
, it will work. I am pretty confused about this and would like someone to explain to me why this happens. Thanks.
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
def encrypt(plain_text, shift_amount):
cipher_text = ""
for letter in plain_text:
position = alphabet.index(letter)
new_position = position + shift_amount
cipher_text += alphabet[new_position]
print(f"The encoded text is {cipher_text}")
def decrypt(cipher_text, shift_amount):
plain_text = ""
for letter in cipher_text:
position = alphabet.index(letter)
new_position = position - shift_amount
plain_text += alphabet[new_position]
print(f"The decoded text is {plain_text}")
if direction == "encode":
encrypt(plain_text=text, shift_amount=shift)
elif direction == "decode":
decrypt(cipher_text=text, shift_amount=shift)