Getting Exception:TypeError: new() missing 1 required positional argument: 'mode'

I want to use AES encryption to encrypt my data I have done it before but in my laptop the method is not working and giving me same error is there any way to fix it ? Here is the code :

from Crypto.Cipher import AES def paddedKey(key):     while len(key)%8!=0:         key +=' '     return key def paddingText(text):     while len(text)%16!=0:         text +=' '     return text data = paddingText(input('Enter text to encrypt - ')) key = paddedKey(input('Enter key between 16-32 charachters - ')) if(len(key)<=16 & len(key)>=32):     print('Key must me between 16 and 32 charachters') cipher = AES.new(key) ciphertext = cipher.encrypt(data) # print(ciphertext) # print(ciphertext.decode('cp855')) print('Encrypted text = ',ciphertext)  

But this code is giving me error : Traceback (most recent call last): File "C:\Users\shati\Desktop\Python\Research\AES_Extended.py", line 18, in cipher = AES.new(key) TypeError: new() missing 1 required positional argument: ‘mode’

I am using pythone version : Python 3.6.8
Pip version: pip 20.1.1
PycryptoDome version : pycryptodome 3.9.8

Add Comment
1 Answer(s)

It’s obvious from error, the new method needs two parameters.

Check this Encrypt & Decrypt using PyCrypto AES 256

You have to pass the mode parameter to the AES.new function.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.