From 44a392aca9059f60390e36bb8372d5ab30d8caed Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Fri, 2 Aug 2019 15:33:11 +0200 Subject: [PATCH] encryption --- encryption.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 encryption.py diff --git a/encryption.py b/encryption.py new file mode 100644 index 0000000..2a05c95 --- /dev/null +++ b/encryption.py @@ -0,0 +1,31 @@ +from Crypto.Cipher import AES +import random +import string + + +def encrypt(password, text): + random.seed(password) + letters = string.ascii_lowercase + password = ''.join(random.choice(letters) for i in range(32)) + add = 16 - (len(text) % 16) + for i in range(add): + text += " " + chiffre = AES.new(password, AES.MODE_ECB) + chiffrat = chiffre.encrypt(text) + return chiffrat + + +def decrypt(password, chiffrat): + random.seed(password) + letters = string.ascii_lowercase + password = ''.join(random.choice(letters) for i in range(32)) + chiffre = AES.new(password, AES.MODE_ECB) + text = chiffre.decrypt(chiffrat) + temp_text = text.decode('ascii') + for counter, letter in enumerate(reversed(text.decode('ascii'))): + if letter == " ": + temp_text = temp_text[:-1] + else: + break + text = temp_text + return text