I want to XOR the password (0x3d), byte by byte, with 0x42, then 0x51, then 0xF7, then 0x6F. this would give me 0xb6..... But, Is there a shortcut to this operation?
Relationship between XOR and "AND"
0
$\begingroup$
logic
computer-science
-
0@FernandoMartin — It was firstly “number-theory elementary-number-theory algebraic-number-theory”, and I retagged it as “algebra-precalculus” because it is only symbol manipulation. I'm not sure “logic computer-science” is much better. There should be a tag “elementary-maths”. – 2012-04-21
2 Answers
1
XOR is associative. Therefore, denoting XOR by ^, you can do
>>> 0x3D ^ 0x42 ^ 0x51 ^ 0xF7 ^ 0x6F 182
but also
>>> 0x3D ^ (0x42 ^ 0x51 ^ 0xF7 ^ 0x6F) 182
which is
>>> 0x3D ^ 0x8B 182
So you can XOR with 0x8B instead. In other words, "multiple xor" is equivalent to a single one.
Associativity follows because XOR is associative on each bit.
-
0@jjitti: using AND only, it is impossible, because AND is monotonic while XOR is not. If you want to express XOR with AND and NOT, then use Fernando's answer. Otherwise I don't know what do you want to do. – 2012-04-21
-1
(p XOR q) = (¬p AND q) OR (p AND ¬q), if that was what you were asking.
-
0Thank you for answering. However, your answer is not what I am looking for. What I am looking for is that the operation above can be reduced using AND operation. I am looking for how to use AND to shortcut this operation... Thanks – 2012-04-21