mirror of
https://github.com/20kaushik02/CSE548_ACNS_Work.git
synced 2025-12-06 07:54:07 +00:00
21 lines
508 B
Python
21 lines
508 B
Python
from Crypto.Cipher import AES
|
|
|
|
|
|
class AESCipher:
|
|
|
|
def __init__(self, key):
|
|
self.key = key
|
|
|
|
def encrypt(self, raw):
|
|
cipher = AES.new(self.key, AES.MODE_ECB)
|
|
if len(raw) % 16 != 0:
|
|
raw += ' ' * (16 - (len(raw) % 16))
|
|
return cipher.encrypt(raw)
|
|
|
|
def decrypt(self, enc):
|
|
cipher = AES.new(self.key, AES.MODE_ECB)
|
|
overflow = len(enc) % 16
|
|
if overflow != 0:
|
|
enc += b' ' * (16 - overflow)
|
|
return cipher.decrypt(enc)
|