[pycrypto] string XOR

Dean Macinskas dmacinskas at geobridge.net
Fri Oct 28 06:57:55 CST 2011


Dwayne,

I've been offline for a few days, so I apologize for the delay.  I'm a new pycrypto user, and missed this - I appreciate the heads-up.

I've got a followup question too: I need to do bit shifts on long (8 or 16 byte) strings.  I can't see any simple way to do this; the built-in Python bit shift functions only work on integers and don't seem to have multi-precision extensions.  Any advice on how to do this?

Thanks again,
Dean

-----Original Message-----
From: pycrypto-bounces at lists.dlitz.net [mailto:pycrypto-bounces at lists.dlitz.net] On Behalf Of Dwayne C. Litzenberger
Sent: Saturday, October 22, 2011 4:24 PM
To: PyCrypto discussion list
Subject: Re: [pycrypto] string XOR

On Fri, Oct 21, 2011 at 03:09:36PM +0100, Richard Moore wrote:
>On Fri, Oct 21, 2011 at 2:55 PM, Dean Macinskas
><dmacinskas at geobridge.net> wrote:
>>     ke = operator.xor(kbpkb,ve)
>>
>> TypeError: unsupported operand type(s) for ^: 'str' and 'str'
>>
>> Is there a way to do this in native Python (I'm using 2.7.2), or must I use
>> a library of some sort?
>
>Use ord() to convert each character to a number first, then chr() to
>convert the number back to a character.

Also, if you're using PyCrypto anyway, you can use its fast C 
implementation of a byte-wise string XOR:

     from Crypto.Util.strxor import strxor

-- 
Dwayne C. Litzenberger <dlitz at dlitz.net>
  OpenPGP: 19E1 1FE8 B3CF F273 ED17  4A24 928C EC13 39C2 5CF7
_______________________________________________
pycrypto mailing list
pycrypto at lists.dlitz.net
http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto


More information about the pycrypto mailing list