[pycrypto] string XOR

Dwayne C. Litzenberger dlitz at dlitz.net
Sat Oct 22 14:23:50 CST 2011

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

More information about the pycrypto mailing list