I'm trying to write an app that needs large numbers of cryptographic strength pseudorandom bytes.
The RC4 cipher would be ideal for this; it's lightweight and simple to understand conceptually. So, I got the spec and wrote an RC4 algorithm in Python.
It works exactly as expected, but, it's slow as molasses. On my Core i7 2.2GHz, I can only get about 1MB/sec out of the algorithm.
Clearly the interpreted nature of Python is not the best suited for this sort of task. My problem is I'm not well versed in C coding - the best I've done with C is some Hello World stuff and some experiments with file reading and writing. Either way, I certainly am not good enough with C to use the Python-C APIs.
I do know .NET/C#, and I wrote the same algorithm in Windows on C#, and I Was able to easily get over 60MB/sec out of it. So .NET's CLR is a lot more optimized. But, the target platform for the Python app is Unix/Linux.
Ideally, I don't want to have to go through tons of middle-layers just to get an optimized RC4 cipher into a Python app.
Since RC4 depends on state, ideally I'd do this with a class (That's how I did it with my Python-only implementation.) So, here's a small snippet of what I want to be able to do:
rc4 = RC4Encrypter()
rc4.seed(myKey) # seed the RC4 algorithm with bytes from string myKey
rc4.getRC4Bytes(1048576) # get the next 1MB of RC4 cryptostream bytes as a binary string
rc4.encryptWithRC4(myString) # encrypt myString's bytes with RC4 bytes using xor and return
Any advice? I'd love to learn C but it's a big learning curve right now for just this simple project.