-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathROT5.py
87 lines (70 loc) · 2.27 KB
/
ROT5.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
# *********
# -*- Made by VoxelPixel
# -*- For YouTube Tutorial
# -*- https://github.com/VoxelPixel
# -*- Support me on Patreon: https://www.patreon.com/voxelpixel
# *********
import re
import sys
def cipher_encryption(rot5, zero_to_nine):
message = input("Enter message: ")
# checking if input is int or not
if not re.search('[\d\s]+', message):
print("Entered message is not an integer")
sys.exit()
# \d = int
# \s = white space
# + = one or more times
# [] a set, with logical OR
encryp_text = ""
for i in range(len(message)):
if message[i] == chr(32):
encryp_text += " "
else:
for j in range(len(zero_to_nine)):
# simple substitution
if message[i] == zero_to_nine[j]:
encryp_text += rot5[j]
# inner if
# inner for
# if-else
# for
print("Encrypted Text: {}".format(encryp_text))
def cipher_decryption(rot5, zero_to_nine):
message = input("Enter message: ")
# checking if input is int or not
if not re.search('[\d\s]+', message):
print("Entered message is not an integer")
sys.exit()
# \d = int
# \s = white space
# + = one or more times
# [] a set, with logical OR
decryp_text = ""
for i in range(len(message)):
if message[i] == chr(32):
decryp_text += " "
else:
for j in range(len(zero_to_nine)):
# simple substitution
if message[i] == rot5[j]:
decryp_text += zero_to_nine[j]
# inner if
# inner for
# if-else
# for
print("Encrypted Text: {}".format(decryp_text))
def main():
rot5 = "5678901234"
zero_to_nine = "0123456789"
choice = int(input("1. Encryption\n2. Decryption\nChoose(1,2): "))
if choice == 1:
print("---Encryption---")
cipher_encryption(rot5, zero_to_nine)
elif choice == 2:
print("---Decryption---")
cipher_decryption(rot5, zero_to_nine)
else:
print("Wrong Choice")
if __name__ == "__main__":
main()