message.txt begins with a line of 26 shuffled capital letters: the cipher alphabet. Letter n of the normal alphabet was replaced by letter n of that line. Reverse the mapping with str.maketrans and the rest of the file, flag included, becomes readable.
| Platform | picoGym (picoCTF 2022) |
| Verified against | ir0nstone's writeup |
| Category | Cryptography |
| Difficulty | Beginner |
| Tools | python3 quipqiup |
A monoalphabetic substitution cipher replaces each letter with another fixed letter. Normally you'd break it with frequency analysis — but this one ships with its key.
Provided: message.txt, whose first line is the key
Stuck? Try a hint before reading the solution
Read the very first line of the file carefully.
It's a 26-letter alphabet: the key. Map each letter back through it.
Print the start of the file:
$ head -n 3 message.txt
[26 SHUFFLED CAPITAL LETTERS]
[encrypted paragraph ...]
A line containing each letter of the alphabet exactly once is the key: plaintext A became the first letter of that line, B the second, and so on.
Build a translation table from the key back to the normal alphabet (for both cases) and apply it to the rest of the file:
import string
lines = open("message.txt").read().split("\n")
key = lines[0].strip()
body = "\n".join(lines[1:])
table = str.maketrans(key + key.lower(),
string.ascii_uppercase + string.ascii_lowercase)
print(body.translate(table))
The paragraph turns into English text, and the flag line near the end reads picoCTF{...}. If the output is still gibberish, you've mapped in the wrong direction — swap the two arguments of maketrans.
If the key weren't given, the same cipher still falls to frequency analysis: the most common letters in English (E, T, A, O...) stay the most common in the ciphertext, and short words like the and and reveal mappings quickly. Online solvers such as quipqiup automate this and are worth knowing for the follow-up challenges.
The flag is deliberately hidden — follow the method, you've earned it. 💪
Always read the whole file before attacking a cipher — sometimes the key is right there:
str.maketrans + translate applies or reverses any letter mappingNew to CTFs? Start here: beginner's guide to CTFs — what a CTF is, the categories, the tools and a step-by-step plan.
Discuss this writeup with the community on the CTFdojo Discord.
Join the Discord →