XOR Keystream Cracking: Known-Plaintext Attack
Repeating-Key XOR — The Classic Mistake
XOR encryption is seductively simple: each byte of plaintext is XORed with a byte from a cycling key. When the key is short and reused, patterns emerge that make the cipher trivially breakable. Many real-world schemes (early game DRM, firmware blobs, malware payloads) have fallen to exactly this attack.
How the Cipher Works
Given a key like "wolf" (4 bytes) and a plaintext, byte i of ciphertext = plaintext[i] XOR key[i % 4]. The key wraps around indefinitely. If you know even a few bytes of plaintext at a known position, you can XOR them against the ciphertext bytes to recover the corresponding key bytes directly.
Your Attack Strategy
All flags in this lab start with the standard prefix FLAG{. That five-character known plaintext is your skeleton key. XOR those five ASCII bytes against the first five bytes of the hex-encoded ciphertext blob to immediately recover the first (up to) five bytes of the repeating key. Once you have the full key, decrypt the entire blob.
In Python: key_byte = ciphertext_byte ^ ord(known_char). In CyberChef, use From Hex → XOR (set to Key mode with your recovered key in hex). Alternatively, openssl or a simple one-liner: python3 -c "import sys; ct=bytes.fromhex('BLOB'); key=b'wolf'; print(bytes(c^key[i%len(key)] for i,c in enumerate(ct)).decode())".
Step-by-Step
- Grab your personal ciphertext hex blob from the lab console.
- XOR the first 4 bytes of the blob against
F,L,A,Gto extract the 4-byte key. - Apply the full repeating XOR with that key to the entire blob.
- Read the plaintext — it is your flag. Submit it.
Sign in to unlock escalating hints for this medium lab.
1f0c171e181d410d12161f12050a0d0b5a0c1e0714044157475e335511580d04125d5d56400e0e1b
XOR the bytes against the key `wolf` (UTF-8, repeating).
// this payload is unique to your account — decode it, then submit the recovered hc{...} flag below