-
Notifications
You must be signed in to change notification settings - Fork 19
/
ROT47.py
60 lines (50 loc) · 1.44 KB
/
ROT47.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
# *********
# -*- Made by VoxelPixel
# -*- For YouTube Tutorial
# -*- https://github.com/VoxelPixel
# -*- Support me on Patreon: https://www.patreon.com/voxelpixel
# *********
def cipher_encryption():
message = input("Enter message: ")
key = 47
encryp_text = ""
for i in range(len(message)):
temp = ord(message[i]) + key
if ord(message[i]) == 32:
encryp_text += " "
elif temp > 126:
temp -= 94
encryp_text += chr(temp)
else:
encryp_text += chr(temp)
# if-else
# for
print("Encrypted Text: {}".format(encryp_text))
def cipher_decryption():
message = input("Enter message: ")
key = 47
decryp_text = ""
for i in range(len(message)):
temp = ord(message[i]) - key
if ord(message[i]) == 32:
decryp_text += " "
elif temp < 32:
temp += 94
decryp_text += chr(temp)
else:
decryp_text += chr(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()