开发者

How can I undo/reverse an XOR with PHP?

开发者 https://www.devze.com 2023-02-15 03:01 出处:网络
I\'m a bit confused by XOR, conceptually. I have an light encryption function I need to decrypt, an开发者_开发技巧d I\'m not sure how to get it working correctly.

I'm a bit confused by XOR, conceptually. I have an light encryption function I need to decrypt, an开发者_开发技巧d 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消