-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencryption.py
31 lines (27 loc) · 886 Bytes
/
encryption.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
27
28
29
30
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