2017-09-15 144 views
-2
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) 

Traceback (most recent call last): File "C:\Users\tommy_000\AppData\Local\Programs\Python\Python35\test13.py", line 6, in cipher = AES.new (key) TypeError: new() missing 1 required positional argument: 'mode'错误我得到我的python代码?错误是这一行:密码= AES.new(键)

回答

0

首先,你必须把对象变成一个变量:

obj = AES() 
cipher = obj.key(key)