Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I undo/reverse an XOR with PHP?

Tags:

php

xor

I'm a bit confused by XOR, conceptually. I have an light encryption function I need to decrypt, and I'm not sure how to get it working correctly.

If my value was originally generated by:

$val = dechex($seed^$id);

Then, elsewhere, I have the corresponding $val and $seed, how can I generate the $id?

like image 868
adam Avatar asked Mar 03 '11 16:03

adam


1 Answers

XOR is its own inverse, so you can just XOR $val by $seed again and get $id. You might need to run hexdec on $val first, though.

like image 123
Jeremiah Willcock Avatar answered Oct 04 '22 05:10

Jeremiah Willcock