Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit acfee13

Browse filesBrowse files
authored
Update algorithms.py
1 parent 197d46c commit acfee13
Copy full SHA for acfee13

File tree

1 file changed

+22
-24
lines changed
Filter options

1 file changed

+22
-24
lines changed

‎algorithms.py

Copy file name to clipboard
+22-24Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
# ===============================================================
2-
# ============ FUNCTION TO DO ASCII BASED ENCRYPTION ===========
3-
# ============ BASED ON A CERTAIN KEY ===========
4-
# ================================================================
1+
from random import seed, randint
52

3+
class __crypt:
4+
"""A way of encrypting and decrypting text in an ASCII way"""
5+
6+
def encrypt(text, key):
7+
"""Encrypts the text, key is used as seed and must be given"""
8+
seed(key)
9+
if not isinstance(text, str):
10+
raise TypeError("{} should be a type string".format(text))
11+
return "".join([chr(ord(something) + randint(1,randint(2,10))) for something in text])
12+
13+
def decrypt(text, key):
14+
"""Decrypts the text, key is used as seed and must be given and must be the same as the encryption."""
15+
seed(key)
16+
if not isinstance(text, str):
17+
raise TypeError("{} should be a type string".format(text))
18+
return "".join([chr(ord(something) - randint(1,randint(2,10))) for something in text])
19+
20+
if __name__ == '__main__':
21+
text = input("Put in some text to encrypt: ")
22+
key = input("Put in a key: ")
623

7-
def encrypt(text, key=0):
8-
if not isinstance(text, str):
9-
raise TypeError("{} should be a type string".format(text))
10-
if not isinstance(key, int):
11-
raise TypeError("{} should be of type int".format(key))
12-
return "".join([chr(ord(something) + key) for something in text])
13-
14-
15-
# ===================================================================
16-
# ============= FUNCTION TO DO ASCII BASED DECRYPTION ===============
17-
# ============= BASED ON A CERTAIN KEY ===============
18-
# ===================================================================
19-
20-
21-
def decrypt(text, key=0):
22-
if not isinstance(text, str):
23-
raise TypeError("{} should be a type string".format(text))
24-
if not isinstance(key, int):
25-
raise TypeError("{} should be of type int".format(key))
26-
return "".join([chr(ord(something) - key) for something in text])
24+
print(f"Encrypted: {__crypt.encrypt(text, key)}")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.