-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathatbash.py
More file actions
47 lines (33 loc) · 1.22 KB
/
atbash.py
File metadata and controls
47 lines (33 loc) · 1.22 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
47
def atbash_encrypt(input_string):
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
reverse_alpha = 'ZYXWVUTSRQPONMLKJIHGFEDCBA'
atbash_string = ''
for char in input_string:
char = char.upper()
if char in alpha:
position = alpha.find(char)
atbash_string += reverse_alpha[position]
else:
atbash_string = None
break
return atbash_string
def atbash_decrypt(atbash_string):
ALPHA='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
REVERSEALPHA='ZYXWVUTSRQPONMLKJIHGFEDCBA'
atbash_string=atbash_string.upper()
decrypted_string=''
for l in atbash_string:
if l in REVERSEALPHA:
letterindex = REVERSEALPHA.find(l)
decrypted_string = decrypted_string + ALPHA[letterindex]
else:
decrypted_string=decrypted_string + l
return decrypted_string
def atbash_wrapper(input_string, method='encrypt'):
if method == 'encrypt':
output_string = atbash_encrypt(input_string)
elif method == 'decrypt':
output_string = atbash_decrypt(input_string)
else:
output_string = "method should be either 'decrypt' or 'encrypt'"
return output_string