-
Notifications
You must be signed in to change notification settings - Fork 2
/
algorithms.py
26 lines (20 loc) · 1.11 KB
/
algorithms.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
# ===============================================================
# ============ FUNCTION TO DO ASCII BASED ENCRYPTION ===========
# ============ BASED ON A CERTAIN KEY ===========
# ================================================================
def encrypt(text, key=0):
if not isinstance(text, str):
raise TypeError("{} should be a type string".format(text))
if not isinstance(key, int):
raise TypeError("{} should be of type int".format(key))
return "".join([chr(ord(something) + key) for something in text])
# ===================================================================
# ============= FUNCTION TO DO ASCII BASED DECRYPTION ===============
# ============= BASED ON A CERTAIN KEY ===============
# ===================================================================
def decrypt(text, key=0):
if not isinstance(text, str):
raise TypeError("{} should be a type string".format(text))
if not isinstance(key, int):
raise TypeError("{} should be of type int".format(key))
return "".join([chr(ord(something) - key) for something in text])