-
Notifications
You must be signed in to change notification settings - Fork 0
/
rot13_lib.py
25 lines (24 loc) · 925 Bytes
/
rot13_lib.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
#two-way table initialisation
alpha_lc = [chr(x) for x in range(97, 123)]
alpha_uc = [chr(x) for x in range(65, 91)]
#numerical encryption
def crypt_word(char, crypt_choice, offset, case):
originalIndex = case.index(char)
if crypt_choice == "encode":
if (originalIndex + offset) > 25:
newIndex = (originalIndex + offset - 26)
output = case[newIndex]
return output
elif (originalIndex + offset) <= 25:
newIndex = (originalIndex + offset)
output = case[newIndex]
return output
if crypt_choice == "decode":
if (originalIndex - offset) < 0:
newIndex = (originalIndex - offset + 26)
output = case[newIndex]
return output
elif (originalIndex - offset) >= 0:
newIndex = (originalIndex - offset)
output = case[newIndex]
return output