-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caeser_Cipher.py
60 lines (49 loc) · 4.88 KB
/
Caeser_Cipher.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
logo = """
██████╗ █████╗ ███████╗███████╗███████╗██████╗ ██████╗██╗██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██╔══██╗██╔════╝██╔════╝██╔════╝██╔══██╗ ██╔════╝██║██╔══██╗██║ ██║██╔════╝██╔══██╗
██║ ███████║█████╗ ███████╗█████╗ ██████╔╝ ██║ ██║██████╔╝███████║█████╗ ██████╔╝
██║ ██╔══██║██╔══╝ ╚════██║██╔══╝ ██╔══██╗ ██║ ██║██╔═══╝ ██╔══██║██╔══╝ ██╔══██╗
╚██████╗██║ ██║███████╗███████║███████╗██║ ██║ ╚██████╗██║██║ ██║ ██║███████╗██║ ██║
╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
██████╗ ██╗ ██╗
██╔══██╗╚██╗ ██╔╝
██████╔╝ ╚████╔╝
██╔══██╗ ╚██╔╝
██████╔╝ ██║
╚═════╝ ╚═╝
██████╗ ██████╗ ██████╗ ███████╗ █████╗ ███╗ ██╗███╗ ██╗██╗ ██╗████████╗██╗
██╔══██╗██╔══██╗██╔═══██╗██╔════╝██╔══██╗████╗ ██║████╗ ██║╚██╗ ██╔╝╚══██╔══╝██║
██████╔╝██████╔╝██║ ██║█████╗ ███████║██╔██╗ ██║██╔██╗ ██║ ╚████╔╝ ██║ ██║
██╔═══╝ ██╔══██╗██║ ██║██╔══╝ ██╔══██║██║╚██╗██║██║╚██╗██║ ╚██╔╝ ██║ ██║
██║ ██║ ██║╚██████╔╝██║ ██║ ██║██║ ╚████║██║ ╚████║ ██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝
"""
print(logo)
#Alphabet list
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']
#Cipher function to encrypt and decrypt
def cipher(start_text, shift_amount, cipher_direction):
end_text = ""
if cipher_direction == 'decode':
shift_amount *= -1
for char in start_text:
if char in alphabet:
position = alphabet.index(char)
new_position = ((position + shift_amount) % 26)
end_text += alphabet[new_position]
else:
end_text += char
print(f"Here's the {direction}d result: {end_text}")
#Loop to restart the program once over
should_end = False
while not should_end:
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"))
#Calling the cipher function
cipher(start_text=text, shift_amount=shift, cipher_direction=direction)
restart = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")
if restart == 'no':
should_end = True
print("Ciao!")