Table of Contents

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

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

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


1) i.e. mostly C-code, partly Python-code
2) You know Bram Cohen, don't you?