-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatbash.py
27 lines (22 loc) · 850 Bytes
/
atbash.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
lookup_table = {'A' : 'Z', 'B' : 'Y', 'C' : 'X', 'D' : 'W', 'E' : 'V',
'F' : 'U', 'G' : 'T', 'H' : 'S', 'I' : 'R', 'J' : 'Q',
'K' : 'P', 'L' : 'O', 'M' : 'N', 'N' : 'M', 'O' : 'L',
'P' : 'K', 'Q' : 'J', 'R' : 'I', 'S' : 'H', 'T' : 'G',
'U' : 'F', 'V' : 'E', 'W' : 'D', 'X' : 'C', 'Y' : 'B', 'Z' : 'A'}
def atbash(message):
cipher = ''
for letter in message:
# checks for space
if(letter != ' '):
#adds the corresponding letter from the lookup_table
cipher += lookup_table[letter]
else:
# adds space
cipher += ' '
return cipher
#encrypt the given message
message = 'GEEKS FOR GEEKS'
print(atbash(message.upper()))
#decrypt the given message
message = 'TVVPH ULI TVVPH'
print(atbash(message.upper()))