-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMono-Alphabatic-cipher.py
More file actions
executable file
·46 lines (40 loc) · 1.64 KB
/
Mono-Alphabatic-cipher.py
File metadata and controls
executable file
·46 lines (40 loc) · 1.64 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
# Monoalphabatic
def monoalphabatic_enc_dec(pt):
'''NO MIXED CASES ARE ALLOWD '''
if pt.islower():
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']
KEY = ['n', 'o', 'a', 't', 'r', 'b', 'e', 'c', 'f', 'u', 'x', 'd', 'q', 'g', 'y', 'l', 'k', 'h', 'v', 'i', 'j',
'm', 'p', 'z', 's', 'w']
ALP_KEY = dict(zip(ALPHABET, KEY))
result = []
for i in range(len(pt)):
char = pt[i]
x = ALP_KEY.get(char)
result.append(x)
KEY_ALP = dict(zip(KEY, ALPHABET))
result1 = []
for i in range(len(result)):
char = result[i]
y = KEY_ALP.get(char)
result1.append(y)
print''.join(result), '=', ''.join(result1)
else:
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']
KEY = ['N', 'O', 'A', 'T', 'R', 'B', 'E', 'C', 'F', 'U', 'X', 'D', 'Q', 'G', 'Y', 'L', 'K', 'H', 'V', 'I', 'J',
'M', 'P', 'Z', 'S', 'W']
ALP_KEY = dict(zip(ALPHABET, KEY))
result = []
for i in range(len(pt)):
char = pt[i]
x = ALP_KEY.get(char)
result.append(x)
KEY_ALP = dict(zip(KEY, ALPHABET))
result1 = []
for i in range(len(result)):
char = result[i]
y = KEY_ALP.get(char)
result1.append(y)
print''.join(result), '=', ''.join(result1)
monoalphabatic_enc_dec('monoalphabatic')