测试输入:
plaintext1234567 1234567891234567
预期输出:
b’e232fb646d5d820620ffa609ba56200a’
b’plaintext1234567’
测试输入:
1234567891234567 plaintext1234567
预期输出:
b’a49e9a7c354a9f64486b16e601fdccd7’
b’1234567891234567’
在这里插入代码片
from Crypto.Cipher import AES
from binascii import b2a_hex, a2b_hex
#ECB模式
class aestest():
#***********Begin**************
def __init__(self, key):
self.key = key.encode('utf-8')
self.mode = AES.MODE_ECB
def en(self, text):
ptor = AES.new(self.key, self.mode)
text = text.encode('utf-8')
self.ciphertext = ptor.encrypt(text)
text = b2a_hex(self.ciphertext)
return text
def de(self, text):
ptor = AES.new(self.key, self.mode)
plain = ptor.decrypt(a2b_hex(text))
return plain
#************End***************
def Evidence(text,key):
# 要求key长度为16
aes = aestest(key)
enc = aes.en(text)
print(enc)
detext = aes.de(enc)
print(detext)