Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving for unknown in bit-wise algebra

Suppose I have 3 bytes, X Y and Z.

X XOR Y results in Z.

I know what X and Z are, but I don't know what Y is, so I'm writing a quick script to figure this out.

Though, I don't know how I would even begin. I did a couple of them by hand and it was simply a matter of comparing each bit one by one, but how can I do this in python? My procedure for solving for Y doesn't seem clear enough.

Since I just need to actually use something like this, it would be enough to either write it or just use something that does this for me.

like image 288
MxLDevs Avatar asked Dec 20 '25 06:12

MxLDevs


1 Answers

If x ^ y == z, then x ^ z == y. You can verify this in Python with

>>> X = range(256)  # all byte values
>>> Y = range(256)
>>> all(x ^ z == y for x in X for y in Y for z in [x^y])
like image 71
Fred Foo Avatar answered Dec 22 '25 18:12

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!