Encryption with Python
Till Plewe
till at score.is.tsukuba.ac.jp
Thu Jun 24 12:10:23 EDT 2004
On Wed, Jun 23, 2004 at 12:50:39AM -0400, Peter Hansen wrote:
> Kamilche wrote:
>
...
> >I've written an encryption algorithm in pure Python that can process
> >22 megs of data a second. I know it's not secure, but it should be
> >enough to ward off casual hacking. Does someone know of something
> >speedier?
>
> In addition to Erik and Paul's comments: if you don't specify
> what machine you ran your benchmark on, the number "22MB/s" is
> completely meaningless...
>
> 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.
are you sure it takes 8s?
>>> from array import array
>>> from time import time
>>> f=file("xxx").read()
>>> len(f)
22000000
>>> s=time();A=array("c",f);t=time(); print t-s
0.0371170043945
>>> s=time();l=list(A);t=time(); print t-s
0.681946992874
That is over ten times faster than your machine. I cannot
believe that. I use
Python 2.3.4 (#2, Jun 24 2004, 13:32:58)
[GCC 3.3.3 [FreeBSD] 20031106] on freebsd5
CPU: AMD Opteron(tm) Processor 248 (2205.01-MHz K8-class CPU)
>>> s=time();A=array("L",f);t=time(); print t-s
0.0372500419617
>>> r=range(22000000/8)
>>> if 1:
... s=time()
... for i in r:
... A[i]^=7877854
... t=time()
... print t-s
...
1.80496907234
>>>
So with a 4Ghz Opteron (or better) he should be able to xor
a 22MB array in one second with some constant.
- Till
More information about the Python-list
mailing list