Change XOR to XNOR

anirudhrata picture anirudhrata · Mar 9, 2013 · Viewed 17.5k times · Source

I am working with a XNOR encrypted file whose key is not known. I want to modify the xortool which is available here: https://github.com/hellman/xortool to work for XNOR encryption.

Apparently, there are only two lines which uses the '^' operator. So I tried changing them to xnor using ~ operator. But I could not get the required output. How can I accomplish this?

Edit: The code uses '^' operator only in line 248 in xortool.py

key_possible_bytes[offset] += chr(ord(char) ^ most_char)

and in line 75 in routine.py

 ret[index] = (chr(ord(char) ^ ord(key[index % len(key)])))

So I added a ~ operator before both of them.

Answer

recursion.ninja picture recursion.ninja · Mar 9, 2013

Replace all instances of a ^ b with ~(a ^ b) to change the XOR operations to XNOR operations. Be sure to insert the not operator at the correct location to ensure correct order of operations occurs!

Using Your specific code examples:

key_possible_bytes[offset] += chr(~(ord(char) ^ most_char))

ret[index] = (chr(~(ord(char) ^ ord(key[index % len(key)]))))