following the white rabbit direct to cables i have this hotdog ..because xor is the base of all hardware encryption
of course i know we're talking about optic tronics
If K is random and you only know A or B (but not both) then, no, there is no way to infer anything about the key - this is the (in)famous one-time-pad.
If you know A and B, then you can recover K very easily. Exclusive-or has those properties:
- ∀n, n⊕n=0
- ∀n, n⊕0=n (identity element)
- ∀a,b, a⊕b=b⊕a (commutativity)
- ∀a,b,c, a⊕b⊕c=(a⊕b)⊕c=a⊕(b⊕c) (associativity)
So we can do the following:
B=A⊕K ⇒ A⊕B=A⊕(A⊕K)=(A⊕A)⊕K=0⊕K=K
So A⊕B=K
Viewed differently, the exclusive-or operator is invertible:
⊕01001110
A0011B0101⊕0110
And since the truth table is symmetric, the exclusive-or operation just happens to be its own inverse, i.e. x⊕−1y=x⊕y. So if we take our original equation:
A⊕K=B
We can represent it as follows:
K⊕A=B
And we can then undo (invert) the exclusive-or by A:
K⊕A⊕−1A=B⊕−1A ⇒ K=B⊕−1A
And as we found above, this is identical to:
K=B⊕A=A⊕B
As found at the beginning.
However, this is assuming A, B and K are all the same length. If K is smaller than A and B, then it means that K will be used multiple times (repeated over the length of the plaintext, presumably). This repetition can be exploited to successfully recover K from only B provided there is enough repetition and there is enough ciphertext to work with - see Vigenere cipher.