-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathalgorithms.py
More file actions
23 lines (20 loc) · 932 Bytes
/
Copy pathalgorithms.py
File metadata and controls
23 lines (20 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from random import seed, randint
class __crypt:
"""A way of encrypting and decrypting text in an ASCII way"""
def encrypt(text, key):
"""Encrypts the text, key is used as seed and must be given"""
seed(key)
if not isinstance(text, str):
raise TypeError("{} should be a type string".format(text))
return "".join([chr(ord(something) + randint(1,randint(2,10))) for something in text])
def decrypt(text, key):
"""Decrypts the text, key is used as seed and must be given and must be the same as the encryption."""
seed(key)
if not isinstance(text, str):
raise TypeError("{} should be a type string".format(text))
return "".join([chr(ord(something) - randint(1,randint(2,10))) for something in text])
if __name__ == '__main__':
a = __crypt.encrypt("Hello world", 5)
print(a)
b = __crypt.decrypt(a, 5)
print(b)