X Marked the Spot (crypto)
A perfect first challenge for beginners. Who said pirates can't ride trains...
Last updated
A perfect first challenge for beginners. Who said pirates can't ride trains...
Last updated
We are given the above encryption code, along with the produced ciphertext. Each character in the flag is XOR'ed with a character in the key. Since the length of the flag is 48 while the length of the key is 8, the key is cycled through 6 times.
Notice that the first 7 characters of the flag are known, along with the last character of the flag. The first 7 characters of the flag would be XOR'ed with the first 7 characters of the key, while the last character of the flag would be XOR'ed with the last character of the key.
To retrieve the first 7 characters of the key, we XOR the first 7 characters of the plaintext with the first 7 characters of the ciphertext. To retrieve the last character of the key, we XOR the last character of the plaintext with the last character of the ciphertext. Once we have retrieved the key, we XOR it with the ciphertext to retrieve the plaintext!
Let be bit in the key, be a bit in the plaintext, and be a bit in the ciphertext. A key property of XOR is that if , then . Therefore if we know the characters in the plaintext and ciphertext at an index , we can perform an XOR operation between them to obtain the -th character in the key, .