Encryption with Python

Peter Hansen peter at engcorp.com
Wed Jun 23 14:18:12 CEST 2004


Paul Rubin wrote:

> Peter Hansen <peter at engcorp.com> writes:
> 
>>Besides, what you say is not possible.  On my machine,
>>which is about a P4 2500MHz, scanning an array.array('c') with
>>22MB of data in it, doing nothing but reading each byte and
>>ignoring it, takes about 8 seconds.  So does converting the
>>array to a list, which is pretty much all C code.  Strings
>>are immutable, so you can't be working with one of them...
> 
> Well, you could do 32-bit operations which are maybe 4x faster.  
> You could maybe get even more speedup using built-in C functions.
> For example, you could do rot13 encryption with the string.translate
> method which should be quite fast.  

Both are good ideas, but I made an assumption that I was starting
with a simple 22MB string, and the cost of converting that to 32-bit
(presumably using array.array still?) would have to be taken into
account, for fairness.  I also assume Kamilche wasn't talking
about using the builtin rot13, since he claimed to have written
this himself...

-Peter



More information about the Python-list mailing list