2017-09-15 169 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) 
相關問題