-
Notifications
You must be signed in to change notification settings - Fork 19
/
ROT18.py
93 lines (79 loc) · 2.56 KB
/
ROT18.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# *********
# -*- Made by VoxelPixel
# -*- For YouTube Tutorial
# -*- https://github.com/VoxelPixel
# -*- Support me on Patreon: https://www.patreon.com/voxelpixel
# *********
import re
def cipher_encryption():
rot5 = "5678901234"
zeroToNine = "0123456789"
rot_13_key = 13
print("Message can be alphanumeric")
message = input("Enter message: ").upper()
encryp_text = "";
for i in range(len(message)):
temp = message[i] + ""
if ord(message[i]) == 32:
encryp_text += " "
elif re.search('[\d\s]+', temp):
# ROT5
for j in range(len(zeroToNine)):
if message[i] == zeroToNine[j]:
encryp_text += rot5[j]
# inner for
elif re.search('[\w\s]+', temp):
# ROT13
ch_temp = ord(message[i]) + rot_13_key
if ord(message[i]) == 32:
encryp_text += " "
elif ch_temp > 90:
ch_temp -= 26
encryp_text += chr(ch_temp)
else:
encryp_text += chr(ch_temp)
# if-else
# for
print("Encrypted Text: {}".format(encryp_text))
def cipher_decryption():
rot5 = "5678901234"
zeroToNine = "0123456789"
rot_13_key = 13
print("Message can be alphanumeric")
message = input("Enter message: ").upper()
decryp_text = "";
for i in range(len(message)):
temp = message[i] + ""
if ord(message[i]) == 32:
decryp_text += " "
elif re.search('[\d\s]+', temp):
# ROT5
for j in range(len(zeroToNine)):
if message[i] == rot5[j]:
decryp_text += zeroToNine[j]
# inner for
elif re.search('[\w\s]+', temp):
# ROT13
ch_temp = ord(message[i]) - rot_13_key
if ord(message[i]) == 32:
decryp_text += " "
elif ch_temp < 65:
ch_temp += 26
decryp_text += chr(ch_temp)
else:
decryp_text += chr(ch_temp)
# if-else
# for
print("Decrypted Text: {}".format(decryp_text))
def main():
choice = int(input("1. Encryption\n2. Decryption\nChoose (1,2): "))
if choice == 1:
print("---Encryption---")
cipher_encryption()
elif choice == 2:
print("---Decryption---")
cipher_decryption()
else:
print("Invalid Choice")
if __name__ == "__main__":
main()