-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption_module.py
More file actions
40 lines (31 loc) · 1.24 KB
/
Copy pathEncryption_module.py
File metadata and controls
40 lines (31 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
from aes_ed import AES
from chacha20_ed import ChaCha20
import random
class Encryption:
def __init__(self):
self.algorithms = {
"00": AES,
"01": ChaCha20
}
#Returns encrypted data and encyption code and key
def encrypt(self, data):
#chooses a random algorithm and encrypt the data
encryption_code=random.choice(tuple(self.algorithms.keys()))
encrypted_data, key=self.algorithms[encryption_code].encrypt(data)
return encrypted_data, encryption_code, key
#Return decrypted data
def decrypt(self, encrypted_data, encryption_code, key):
decrypted_data=self.algorithms[encryption_code].decrypt(encrypted_data, key)
return decrypted_data
'''
def sample_encryption():
encryption_module = Encryption()
data = b"This is a compressed text string example."
encrypted_data, encryption_code, key = encryption_module.encrypt(data)
print(f"Encrypted data: {encrypted_data}\n")
print(f"Encryption code: {encryption_code}\n")
print(f"key: {key}\n")
decrypted_data=encryption_module.decrypt(encrypted_data, encryption_code, key)
print(f"Decrypted data: {decrypted_data}\n")
sample_encryption()
'''