How to find a value that XORs to another value?

Viewed 65

I'm trying to have 3 keys that XOR to the master key value.

A XOR B XOR C = MASTER KEY

If A, B and the MASTER KEY can be generated as a randomByte(LENGTH=32), how can I find the C value? (in javascript)

2 Answers

Since XOR is its own inverse (that is A XOR A = 0 for all bit patterns, A), you can find C by the following:

C = A ^ B ^ MASTER_KEY;

Where ^ is the JavaScript XOR operator, and A, B, and MASTER_KEY are the values you defined above.

Since XOR is the inverse operation of XOR and XOR is commutative, you can just apply basic arithmetics:

A XOR B XOR C = M    | XOR C
A XOR B = M XOR C    | XOR M
A XOR B XOR M = C

And in javascript syntax:

var C = A ^ B ^ MASTER_KEY;
Related