from Cryptodome.Cipher import AES
key = b' \xbf\xc0\x85'
message = 'This secret message is encrypted'
cipher = AES.new (key)
def pad(s):
return s + ((16-len(s) % 16) * '{')
def encrypt(plaintext):
global cipher
return cipher.encrypt(pad(plaintext))
def decrypt(ciphertext):
global cipher
dec = cipher.decrypt(ciphertext).decode('utf-8')
l = dec.count('{')
return dec[:len(dec)-l]
print("Message:",message)
encrypted = encrypt(message)
decrypted = decrypt(encrypted)
print("Encrypted:", encrypted)
print("Decrypted:", decrypted)
追踪(最近一次通话): 文件“C:\ Users \ tommy_000 \ AppData \ Local \ Programs \ Python \ Python35 \ test13.py”,第6行,in 密码= AES.new(密钥) TypeError:new()缺少1个必需的位置参数:'mode'
答案 0 :(得分:0)
首先,您必须将对象放入变量:
obj = AES()
cipher = obj.key(key)