[PYTHON-CRYPTO] Question using an AES decryption

Sascha Silbe sascha-ml-cryptography-python-crypto at SILBE.ORG
Thu Feb 15 21:31:49 CET 2007

On Thu, Feb 15, 2007 at 08:39:02PM +0100, Alex wrote:

> obj = AES.new('1234567812345678', AES.MODE_CBC, 'bbbbbbbbaaaaaaaa')
With Cipher Block Chaining (CBC), each block gets XORed to the previous 
block. The first one against the Initialisation Vector (IV), of course.

> print "Before encryption: ", plain
> ciph = obj.encrypt(plain)
After this instruction, you've modified the state of obj to use <ciph> 
instead of the IV.

> print "After decryption: ", ciph
> print "After decryption: ", obj.decrypt(ciph)

If you use two independent instances, it works fine:

=== Begin x.py ===
# Encrypt some text with 256bit AES
from Crypto.Cipher import *
plain="this is some textXXXXXXXXXXXXXXX"  # make text len multiple of 16
obj1 = AES.new('1234567812345678', AES.MODE_CBC, 'bbbbbbbbaaaaaaaa')
obj2 = AES.new('1234567812345678', AES.MODE_CBC, 'bbbbbbbbaaaaaaaa')
print "Before encryption: ", `plain`
ciph = obj1.encrypt(plain)
print "After decryption: ", `ciph`
print "After decryption: ", `obj2.decrypt(ciph)`
=== End x.py ===

=== Begin screenshot ===
Before encryption:  'this is some textXXXXXXXXXXXXXXX'
After decryption:  
After decryption:  'this is some textXXXXXXXXXXXXXXX'
=== End x.py ===

CU Sascha


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-crypto/attachments/20070215/830803cf/attachment.pgp>

More information about the python-crypto mailing list