|
| 1 | +alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', |
| 2 | + 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', |
| 3 | + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] |
| 4 | + |
| 5 | +def caesar(text1, shift1, direction1): |
| 6 | + end_text = '' |
| 7 | + if direction=='decode': |
| 8 | + shift1 *= -1 |
| 9 | + |
| 10 | + for char in text1: |
| 11 | + if char in alphabet: |
| 12 | + position = alphabet.index(char) |
| 13 | + new_position = position + shift1 |
| 14 | + end_text += alphabet[new_position] |
| 15 | + else: |
| 16 | + end_text += char |
| 17 | + print(f'The {direction1}d text is: {end_text}.') |
| 18 | + |
| 19 | + |
| 20 | +should_continue = True |
| 21 | +while should_continue: |
| 22 | + direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n") |
| 23 | + text = input("Type your message:\n").lower() |
| 24 | + shift = int(input("Type the shift number:\n")) |
| 25 | + shift = shift % 25 |
| 26 | + |
| 27 | + caesar(text, shift, direction) |
| 28 | + choice=input("Type 'yes' to continue otherwise type 'no'.\n") |
| 29 | + if choice == 'no': |
| 30 | + should_continue=False |
0 commit comments