|
| 1 | +alphabet = [ |
| 2 | + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', |
| 3 | + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', |
| 4 | + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', |
| 5 | + 't', 'u', 'v', 'w', 'x', 'y', 'z' |
| 6 | +] |
| 7 | + |
| 8 | + |
| 9 | +def caesar(start_text, shift_amount, cipher_direction): |
| 10 | + end_text = "" |
| 11 | + if cipher_direction == "decode": |
| 12 | + shift_amount *= -1 |
| 13 | + for char in start_text: |
| 14 | + if char in alphabet: |
| 15 | + position = alphabet.index(char) |
| 16 | + new_position = position + shift_amount |
| 17 | + end_text += alphabet[new_position] |
| 18 | + else: |
| 19 | + end_text += char |
| 20 | + |
| 21 | + print(f"Here's the {cipher_direction}d result: {end_text}") |
| 22 | + |
| 23 | +should_continue = True |
| 24 | +while should_continue: |
| 25 | + from art import logo |
| 26 | + print(logo) |
| 27 | + |
| 28 | + direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n") |
| 29 | + text = input("Type your message:\n").lower() |
| 30 | + shift = int(input("Type the shift number:\n")) |
| 31 | + shift % 27 |
| 32 | + |
| 33 | + caesar(start_text=text, shift_amount=shift, cipher_direction=direction) |
| 34 | + decision = input("Do you wanna start again? (yes/no)\n") |
| 35 | + if decision == "no": |
| 36 | + should_continue = False |
| 37 | + print("Goodbye") |
| 38 | + |
| 39 | + |
0 commit comments