1002. XOR Decryption: Single-Byte Key
Hard · String
A message has been XOR-encrypted with a single repeated byte key. Recover the plaintext.
Strategy: try every possible key byte (0–255). Score each candidate by the fraction of printable ASCII characters it produces. Return the candidate with the highest printable ratio.
Input (stdin, JSON): { "ciphertextHex": "1b3733331b6e2331..." }
Output (stdout): the recovered plaintext string.
Hint: this is the foundational primitive behind many CTF crypto challenges.
Examples
Example 1
Input: {"ciphertextHex":"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"}
Output: Cooking MC's like a pound of bacon
Explanation: Cryptopals classic — single-byte XOR.Constraints
- Hex input, length 2..2048.
- Plaintext is printable ASCII.