Challenges
CTR: nonce reuse
Cryptography
Medium
Mode errors
Solves: 8
CTR: nonce reuse
Author: CyberSamSU
Points
45
In CTR mode, the keystream depends only on the key and the nonce. If two messages are encrypted with the same key and the same nonce, both are XORed with exactly the same keystream. This causes the "two-time pad" problem.
The mathematics is very simple:
C1 = P1 XOR KS
C2 = P2 XOR KS
C1 XOR C2 = P1 XOR P2 <-- kalit butunlay yo'qoldi!
Therefore, if the text of one message is known to us, we can read the second one without any key.
First message (known, UTF-8):
Assalomu alaykum! Bu birinchi xabar, uning matni hammaga ma'lum. Ikkinchi xabar esa sir saqlanmoqda.
Its ciphertext (hex):
647ba37e813441fdc6a128cd7a46fbf489d738240557688eb6a043bd35fde081
4c76a427614e42baf1feb04694a1d2f07232044d9837ff5227ca3adcce0b0358
677585352aeca4a38bdac797fcfd707e6be48926e6809b7c451c8ab8eb7be64d
bc02ef63
The second message's ciphertext (hex) — with the exact same key and nonce:
6749894da20a57c9d5931bc23343edfcf7c6113a146a6cc8adba148a6daef08c
1a63e7672c0f5fe2f1e4
The message lengths are different — perform the XOR up to the length of the shorter one (zip() does this itself).
To submit a flag, log in.