-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monoalphabetic_Cipher.py
39 lines (28 loc) · 1.2 KB
/
Monoalphabetic_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
import random
while True:
ch = int(input("Press 1 for Encrypt || 2 for Decrypt:-\n>>>"))
if ch == 1:
text = input("Text:").lower()
alpha = [a for a in range(97,123)]
charactrize=[ chr(al) for al in alpha]
charactrize.append(' ')
shuffled = random.sample(alpha,len(alpha))
key =[chr(sh) for sh in shuffled]
key.append(' ')
print("\n============================================")
print(" !!!Encrypted!!! ")
for tx in text:
print(key[charactrize.index(tx)],end="")
print("\n============================================")
print("Using Key:",key,"\n")
elif ch == 2:
text = input("text:").lower()
key = eval(input("Key:"))
alpha = [a for a in range(97,123)]
charactrize=[chr(al) for al in alpha]
charactrize.append(' ')
print("\n============================================")
print(" !!!Decrypted!!! ")
for tx in text:
print(charactrize[key.index(tx)],end="")
print("\n============================================\n")