Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change XOR to XNOR

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.

like image 215
anirudhrata Avatar asked Sep 02 '25 06:09

anirudhrata


1 Answers

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)]))))

like image 76
recursion.ninja Avatar answered Sep 04 '25 21:09

recursion.ninja