Encrypting user input in Python with pyCrypto
Question: I am trying to do basic encryption in Python, in below program I encrypt
whatever user types in, and then I am displaying it back to the user after
decryption. I am using the pyCrypto library which I downloaded from here:
<http://www.voidspace.org.uk/python/modules.shtml#pycrypto>

Below is the code I have written so far:

    
    
    from Crypto.Cipher import AES
    
    AES_key = AES.new('This is a key')
    #message = "The answer is no"
    message = input("Enter text:")
    
    ciphertext = AES_key.encrypt(message)
    print (ciphertext)
    
    decrypted_message = AES_key.decrypt(ciphertext)
    print (decrypted_message)
    

The problem is when I taken input from the user, my code does not work, but
when I give static input the one which I have commented my code works fine.

Can anyone please help what should I do so that my accepts user input and
encrypts it?


Answer: `AES` is a block cipher algorithm so it requires you to have the text to be a
multiple of 16 bytes. your message `"The answer is no"` is of 16 bytes.But the
input wouldn't be so you can use the `MOD_CFB` of the `AES` to get around
this.

    
    
    from Crypto.Cipher import AES
    # Encryption
    encryption_suite = AES.new('This is a key123', AES.MODE_CFB, 'This is an IV456')
    cipher_text = encryption_suite.encrypt("A really secret message. Not for prying eyes.")
    
    # Decryption
    decryption_suite = AES.new('This is a key123', AES.MODE_CFB, 'This is an IV456')
    plain_text = decryption_suite.decrypt(cipher_text)
    

this would work for user input.

For more info on `IV`(initialization vectors) go
[Here](http://www.cryptofails.com/post/70059609995/crypto-
noobs-1-initialization-vectors)

