AES / Rijndael

Usually, you should use PyCrypto from the python-crypto package. But if you want to code in Python3, there's no fast hybrid1) implementation of such a library.

Using Google, you will most probably stumble on Bram Cohen's Rijndael implementation in pure Python.2) I took his code and made it Python3 ready by replacing all xrange() by range(), all divisions (/) by integer-divisions (//) and made the string.join() working. There were no more changes neccessary.

See the working Python class here: rijndael.py (10.69 KiB, 1386 downloads)

Another Rijndael implementation I found was pyRijndael. After changing the two long() to int() and adding parentheses to all the prints at the end of the file, it worked fine with Python3.

AESEncryptCtr / AESDecryptCtr

Chris Veness had created a JavaScript implementation of AES in counter operation mode some time ago. He also ported this script to PHP so that you can interchange information between those two systems.

I ported the same library to Python to let Python talk to a PHP server in an encrypted way.

Download it here: aes.py (7.59 KiB, 1092 downloads)

Usage

import aes
text = "Hello, world!"
password = "itsmysecret"
blocksize = 256   # can be 128, 192 or 256
crypted = aes.encrypt( text, password, blocksize )
# do something
decrypted = aes.decrypt( crypted, password, blocksize )

See Also


blog comments powered by Disqus
1) i.e. mostly C-code, partly Python-code
2) You know Bram Cohen, don't you?
snippets/python/aes-rijndael.txt · Last modified: 2013-03-16 17:27.03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA