Easy Peasy (40)
One-time-pad (OTP) key reuse
Last updated
Was this helpful?
One-time-pad (OTP) key reuse
Last updated
Was this helpful?
A one-time pad is unbreakable, but can you manage to recover the flag? (Wrap with picoCTF{}) nc mercury.picoctf.net 20266
Source code:
A few things here:
startup()
and encrypt()
increment the key offset by the length of the data encrypted.
We know that the flag is 32 bytes, since the ciphertext is printed to us.
Once the key is reused, we can use the Crib Drag Attack to decode the ciphertext.
So, the goal is to make the key be used twice. This can easily be achieved by calculating the remaining bytes until stop % KEY_LEN
eventually becomes 0. This means we have to encrypt a total of 50000 - 32 bytes of data.
then we can XOR the two ciphertexts to get
The script will calculate the number of bytes so that the key is reused against our custom payload.
1) c1 = flag XOR key = 5b1e564b6e415c0e394e0401384b08553a4e5c597b6d4a5c5a684d50013d6e4b
2) c2 = custom payload ('b' * 32
) XOR key = 0045041e3e1a075a3e1a00543e1a53003e1a5b5a293e1a065a3e1a03543c3e1a
3) m1 XOR m2 = c1 XOR c2 = 5b5b5255505b5b540754045506515b55045407035253505a0056575355015051
4) m1 XOR m2 XOR m2 = m1 = 99072996e6f7d397f6ea0128b4517c23
This is the flag!
If the key is reused such that
In this case, we can control . Since and , then
Sidenote: if we don't know , we can use the crib drag attack to guess parts of the message at a time.