From f6bf10b2f82e60ead5f68fd7456163f9c7dbf7f3 Mon Sep 17 00:00:00 2001 From: 1Codealot <58225804+1Codealot@users.noreply.github.com> Date: Mon, 5 Jun 2023 17:11:51 +0100 Subject: [PATCH 1/2] Made the encryption harder to see by using random. Made a class __crypt because en and de are two letters. Used randomness to make it less like a glorified Caeser Cipher. --- algorithms.py | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/algorithms.py b/algorithms.py index ae913df..767fbc7 100644 --- a/algorithms.py +++ b/algorithms.py @@ -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,30))) 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,30))) for something in text]) + +if __name__ == '__main__': + a = __crypt.encrypt("Hello world", 5) + print(a) + b = __crypt.decrypt(a, 5) + print(b) From 52a96f11b4adc019b7782d59fc16a5a3fbb3056c Mon Sep 17 00:00:00 2001 From: 1Codealot <58225804+1Codealot@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:40:42 +0100 Subject: [PATCH 2/2] Update algorithms.py Basically there were numbers that were pulled fresh from my butt which made it annoying to add the encrypted text to a new file. --- algorithms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithms.py b/algorithms.py index 767fbc7..544d003 100644 --- a/algorithms.py +++ b/algorithms.py @@ -7,14 +7,14 @@ def encrypt(text, key): 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,30))) for something in 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,30))) for something in text]) + return "".join([chr(ord(something) - randint(1,randint(2,10))) for something in text]) if __name__ == '__main__': a = __crypt.encrypt("Hello world", 5)