-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesar_Cipher
More file actions
52 lines (45 loc) · 2.16 KB
/
Caesar_Cipher
File metadata and controls
52 lines (45 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
print(r""" $$$$$$\ $$$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$\
$$ __$$\$$ _____$$ __$$\$$ __$$\$$ __$$\$$ __$$\
$$ / \__$$ | $$ / $$ $$ / \__$$ / $$ $$ | $$ |
$$ | $$$$$\ $$$$$$$$ \$$$$$$\ $$$$$$$$ $$$$$$$ |
$$ | $$ __| $$ __$$ |\____$$\$$ __$$ $$ __$$<
$$ | $$\$$ | $$ | $$ $$\ $$ $$ | $$ $$ | $$ |
\$$$$$$ $$$$$$$$\$$ | $$ \$$$$$$ $$ | $$ $$ | $$ |
$$$$$$\/$$$$$$\$$$$$$$\\$$\\__$$\$$$$$$$$\$$$$$$$\\__|
$$ __$$\\_$$ _$$ __$$\$$ | $$ $$ _____$$ __$$\
$$ / \__| $$ | $$ | $$ $$ | $$ $$ | $$ | $$ |
$$ | $$ | $$$$$$$ $$$$$$$$ $$$$$\ $$$$$$$ |
$$ | $$ | $$ ____/$$ __$$ $$ __| $$ __$$<
$$ | $$\ $$ | $$ | $$ | $$ $$ | $$ | $$ |
\$$$$$$ $$$$$$\$$ | $$ | $$ $$$$$$$$\$$ | $$ |
\______/\______\__| \__| \__\________\__| \__| """)
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']
def caesar_cipher(choice, original_text, shift_amount):
output_text = ""
if choice == "decode":
shift_amount *= -1
shift_amount %= 26
for letter in original_text:
if letter in alphabet:
position = (alphabet.index(letter) + shift_amount) % 26
output_text += alphabet[position]
else:
output_text += letter
return output_text
while True:
direction = input("Type 'encode' to encode or type 'decode' to decode:\n").lower()
if direction not in ["decode", "encode"]:
print("Invalid command, please enter 'encode' or 'decode':\n")
continue
message = input("Enter your message:\n").lower()
shift = int(input("Enter shift number:\n"))
result = caesar_cipher(direction,message,shift)
print(f"Your {direction}d message is {result}")
restart = input("Would you like to continue with the cipher? Type 'yes' or 'no':\n").lower()
if restart not in ["yes", "no"]:
print("You've entered an invalid command, exiting program.")
break
if restart == "no":
print("Bye, Bye.")
break