Some easy math can provide you an answer.
Let us say you have a sequence of N bits.
p(n) can be the probability that bit number
n among the
N has value 1. Then obviously
1-p(n) is a probability that it is a 0.
Now let us do a XOR of the previous sequence of N bits with a sequence of same length that is random. For this second sequence,
p'(n) = 0.5 as there is equal probability to have a
0 or a
To compute the
p''(n) probably for the result to be a bit at value one, we need to search for cases where the result is 1.
There are two cases:
- bit from first sequence is 1 (probability
p(n)) and bit from second sequence is 0 (probability
- OR bit from first sequence is 0 (probability
1-p(n)) and bit from second sequence is 1 (probability
So the probability
p''(n) that the resulting bit at position
n has value 1 is
p(n) × (1-p'(n)) + (1-p(n)) × p'(n)
p'(n) = 0.5 = 1-p'(n) (we said it is random), the above formula simplifies itself easily:
p''(n) = p(n) × (1 - p'(n)) + (1 - p(n)) × p'(n)
p''(n) = p(n) × 0.5 + (1 - p(n)) × 0.5
p''(n) = p(n) × 0.5 + 0.5 - 0.5 × p(n)
p''(n) = 0.5
The resulting string is random, as soon as one of the two being XORed was random.
This is the core property of the XOR operation, coming from its logic table, that explains why perfect encryption is achieved with XORing something with a random string as the result is random and hence could be decrypted equally to any value in the complete space of values.
And of course it is impractical to use because it needs a random sequence of the same length than what needs to be encrypted, never to be reused, and to be shared between the sender and the recipient.