Break the Repeating-Key XOR Cipher
Repeating-Key XOR: A Classic Weakness
XOR encryption is beautifully simple: every byte of plaintext is XORed with a byte from a repeating key. If the key is short and the plaintext is known to follow a predictable pattern (like printable ASCII), the cipher crumbles quickly.
Why It Breaks
When the same key byte encrypts many plaintext bytes, statistical patterns survive. For a key length of n, bytes at positions 0, n, 2n, … were all encrypted with the same key byte. If the plaintext is ASCII, the most common byte in each group is likely 0x20 (space) or the character e — XORing your guess against the most-frequent ciphertext byte reveals the key byte. Repeat for each position and you recover the full key.
How to Decode
Your intercepted blob is delivered as a hex string. The workflow is:
- Hex-decode the blob — in Python:
bytes.fromhex(blob)or CyberChef's From Hex operation. - Identify key length — try lengths 1–8; for each, split ciphertext into columns and score each column's byte frequencies against expected English/ASCII.
- XOR each column with the best-guess key byte to recover the key, then XOR the full ciphertext with the repeating key.
- In Python:
''.join(chr(b ^ ord(k)) for b, k in zip(ct, itertools.cycle(key)))— the flag will appear in the plaintext.
Tools
- Python 3 (recommended):
itertools.cycle,bytes.fromhex, list comprehensions. - CyberChef: chain From Hex → XOR with your discovered key set to UTF-8 / Cycling.
- xortool (
pip install xortool): automates key-length detection and key recovery in one step.
Sign in to unlock escalating hints for this medium lab.
1f570d1d18465b0e124d0511055117085a0546542857420144011457140710074e49
XOR the bytes against the key `w4ve` (UTF-8, repeating).
// this payload is unique to your account — decode it, then submit the recovered hc{...} flag below