XORing long strings opimization?
Francis Avila
francisgavila at yahoo.com
Tue Nov 4 17:37:13 EST 2003
"Noen" <not.available at na.no> wrote in message
news:ieUpb.24457$BD3.4567875 at juliett.dax.net...
> nope, thought the Argument check would do it, but I used and opeartor
> instead of or. Well, here is XOR v.0.3b :P Any comments how to make it
> faster?
How about using the struct module?
Caveat: I don't know if struct limits the repeat count.
import struct
def XOR(data, key):
if len(data) != len(key):
raise ValueError, "data and key not of equal length"
ldata = struct.unpack('=%sb' % len(data), data)
lkey = struct.unpack('=%sb' % len(key), key)
lxored = [d^k for d,k in zip(ldata, lkey)]
xored = struct.pack('=%sb' % len(lxored), *lxored)
return xored
Just an idea.
--
Francis Avila
More information about the Python-list
mailing list