
One Time Pads
One time pads are considered unbreak-able, if and only if, used correctly.
The encryption process is as follows:
m = message
k = key
ciphertext c = m ^ k where ^ is the XOR operator.
This assumes the length of k is atleast equal to m and that k is only ever used once.
Decryption is simply the reverse:
m = c ^ k
Attacks
a. Manytime pad (key re-use for 3 or more messages)
b. Twotime pad (key re-use for 2 messages)
c. Repeating key for a single message
a. Manytime pad (key re-use for 3 or more messages)
Because applying XOR twice basically undoes the first XOR (each element is its own inverse under XOR), this opens up vulnerabilities related to key re-use.
In example:
(binary) 110 ^ 111 = 001
and repeating it: 001 ^ 111 = 110
This means that if we use the same key twice or more to XOR a message, we can XOR messages with eachother to undo the encryption step and leaving a sum of plaintexts.
For example since:
c₀ = m₀ ^ k
c₁ = m₁ ^ k
This means c₀ ^ c₁ = ( m₀ ^ k ) ^ (m₁ ^ k) since k is its own inverse when applying XOR, we can drop k:
c₀ ^ c₁ = m₀ ^ m₁
Hence XORing two ciphertexts encrypted with the same key gives us the XOR results of both plaintexts and this is infinitely easier to attack then ciphertext.
The easiest variant of this is when the same key is used more then two times
Code:
to do
b. Twotime pad (key re-use for 2 messages)
See a. Manytime pad (key re-use for 3 or more messages) for a full explanation. The code below simply covers the more restricted case when the key is only re-used twice.
Code:
to do
c. Repeating key for a single message
If the key is re-used for a single message, for example when Bob wants to encrypts a message where the message length is longer then the key and chooses to simply loop the key as a solution, then we can try to guess the key length and abuse the same principles as in a. Manytime pad (key re-use for 3 or more messages).
Code:
to do