Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the encryption harder to see by using random. #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions algorithms.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# ===============================================================
# ============ FUNCTION TO DO ASCII BASED ENCRYPTION ===========
# ============ BASED ON A CERTAIN KEY ===========
# ================================================================
from random import seed, randint


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])
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)