Re: Question using an AES decryption

Sascha Silbe <[email protected]>
Newsgroups gmane.comp.python.cryptography
Message-ID <[email protected]>
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:  
"\x81\xb89\x8c\x86\xbe{.'P\xc3\x04W\xc4\tt\x94\xe6e\xe4V\xf1\xa4\x1bB\x90x\x95\xb9Q\xda\x96"
After decryption:  'this is some textXXXXXXXXXXXXXXX'
=== End x.py ===



CU Sascha

-- 
http://sascha.silbe.org/
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6-ecc01.6 (GNU/Linux)

iD8DBQFF1MNMebr7S6V0daMRAphoAJ952jogpQQnX956Jfczn93TyTWXewCbB9PP
FMHDGQxZhHiTqKQ6w4dBxFo=
=6/eI
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.