-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesar-cipher.py
More file actions
40 lines (35 loc) · 2.39 KB
/
Caesar-cipher.py
File metadata and controls
40 lines (35 loc) · 2.39 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
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']
logo = '''
██████╗ █████╗ ███████╗███████╗ █████╗ ██████╗
██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗██╔══██╗
██║ ███████║█████╗ ███████╗███████║██████╔╝
██║ ██╔══██║██╔══╝ ╚════██║██╔══██║██╔══██╗
╚██████╗██║ ██║███████╗███████║██║ ██║██║ ██║
╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
██████╗██╗██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██║██╔══██╗██║ ██║██╔════╝██╔══██╗
██║ ██║██████╔╝███████║█████╗ ██████╔╝
██║ ██║██╔═══╝ ██╔══██║██╔══╝ ██╔══██╗
╚██████╗██║██║ ██║ ██║███████╗██║ ██║
╚═════╝╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
'''
print (logo)
def caesar_cipher(text, shift, direction = "encode"):
cipher_text = ""
if direction == "decode":
shift *= -1
for i in text:
if i in alphabet:
cipher_text += alphabet[((alphabet.index(i))+shift)%26]
else:
cipher_text += i
print(f"The {direction}d text is {cipher_text}")
x = 1
while (x == 1):
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt: ").lower()
text = input("Type your message: ").lower()
shift = int(input("Type the shift number: "))
caesar_cipher(text, shift, direction )
x = int(input("Type 1 to continue, type 0 to exit: "))
print ("Game Over !! Thanks for Playing.")