-
Notifications
You must be signed in to change notification settings - Fork 0
/
caesar_cipher.py
52 lines (38 loc) · 1.46 KB
/
caesar_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
import sys
print("\t\t\t👩💻Hey there. Welcome to clown caesar cipher👨🏻💻\n")
alpha = ['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 encryption(plain,shift):
cipher = ""
for char in plain:
if char in alpha:
pos = alpha.index(char)
brapos = (pos+shift)%26
cipher += alpha[brapos]
else:
cipher += char
print(f"\tYowww!! Here's the text after encryption:👉🏻👉🏻 {cipher}\n")
def decryption(cipher,shift):
plain = ""
for char in cipher:
if char in alpha:
pos = alpha.index(char)
brapos = (pos-shift)%26
plain += alpha[brapos]
else:
plain += char
print(f"\tYowww!! Here's the text after decryption:👉🏻👉🏻 {plain}\n")
finish = False
while not finish:
cryption = input("\tType 'encrypt' for encryption, type 'decrypt' for decryption: \n")
message = input("\tType your message: \n").lower()
shift_no = int(input("\tType the shift number: \n"))
if cryption=="encrypt":
encryption(plain= message,shift=shift_no)
elif cryption=="decrypt":
decryption(cipher=message,shift=shift_no)
again = input("Type 'yes' to play again, else 'no' to quit: \n")
if again=="no":
finish=True
print("Byee.!!👋👋👋")
sys.exit()