【发布时间】:2020-12-02 19:29:55
【问题描述】:
ecb 模式有错误吗? 为什么即使我做了所有事情我的程序也无法正常工作......我被卡住了请帮忙。
我加密的文本:你好世界
我的尝试:
from Crypto.Cipher import AES
import base64
key = '0123456789abcdef'
#this is the password that we are going to use to encrypt and decrpyt the text
def encrypt(text):
global key
cipher = AES.new(key, AES.MODE_ECB)
if len(text) %16!=0:
while not len(text)%16==0:
text=text+" "
encrypted_text =cipher.encrypt(text)
return encrypted_text.strip()
def decrypt(text):
global key
decipher = AES.new(key, AES.MODE_ECB)
if len(text)%16!=0:
while len(text)%16!=0:
text=str(text)+" "
return decipher.decrypt(text).strip()
text=input("Enter encrypted text here : ")
#b'XhXAv\xd2\xac\xa3\xc2WY*\x9d\x8a\x02'
print(decrypt(text))
输入:
b'XhXAv\xd2\xac\xa3\xc2WY*\x9d\x8a\x02'
输出:
b"yR\xca\xb1\xf6\xcal<I\x93A1`\x1e\x17R\xbb\xc8(0\x94\x19'\xb3QT\xeb\x9b\xfe\xc8\xce\xf4l9\x92\xe8@\x18\xf2\x85\xbe\x13\x00\x8d\xa8\x96M9"
所需输出:
hello world
【问题讨论】:
-
这是 python 2 还是 3?
input函数在两者之间做完全不同的事情。欧洲央行也不安全。