With this cipher, it's pretty easy to retrieve at least 1 key that is consistent with 2 pairs of plaintext,ciphertext .
(Other ciphers are better or worse at making it nearly impossible to recover even 1 key consistent with the given plaintext,ciphertext).
With this cipher, it is not possible to fully retrieve the key from only 2 known pairs of plaintext,ciphertext.
(Other ciphers are better or worse at keeping the key secret after plaintext,ciphertext pairs are leaked).
For example:
( n=2 for simplicity )
c1 = ( 00 xor 01 ) + 10 (mod 2^2) == 11
c2 = ( 10 xor 01 ) + 10 (mod 2^2) == 01
c3 = ( 11 xor 01 ) + 10 (mod 2^2) == 00
So (plaintext, ciphertext) pairs 00-->11 and 10-->01
are consistent with K0==01, K1==10.
However,
c1 = ( 00 xor 00 ) + 11 (mod 2^2) == 11
c2 = ( 10 xor 00 ) + 11 (mod 2^2) == 01
c3 = ( 11 xor 00 ) + 11 (mod 2^2) == 10
So (plaintext, ciphertext) pairs 00-->11 and 10-->01
are also consistent with K0==00, K1==11.
As you can see, the third pair 11-->00 or 11-->10 can distinguish between these two possibilities,
so they are not equivalent keys.
(On the other hand, the key K0=00, K1==11 is equivalent to the key K0=10, K1=01 -- given any plaintext, either key gives identically the same ciphertext as the other set of keys).
A quick way to find a key consistent with a given set of plaintext,ciphertext pairs (but not necessarily the key) is:
- start with a candidate key K0 == 0 and K1 == all-ones, then use the following procedure to iteratively improve them.
- Start with B0 as the most-significant bit position, and start with B1 as the next-most-significant bit position. (Every time through the loop, move B0 and B1 by 1 bit to the next-most-significant position).
Loop: