Python-exercises/Ceasar-cipher.py

25 lines
649 B
Python

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']
direction = input ("Type 'encode' to encrypt, type 'decode' to decrypt:\n").lower()
text = input("Type your message: \n").lower()
shift = int(input("Type the shift number: \n"))
def encrypt(original_text, shift_amount):
cipher_text = ""
for letter in original_text:
shifted_position = alphabet.index(letter) + shift_amount #7 -> 9
cipher_text += alphabet[shifted_position] # j
print(f"{cipher_text}")
encrypt(original_text = text, shift_amount = shift)