picoCTF Substitution0 Writeup: Decrypt with the Key on the First Line

Crypto 2026-09-14 · Updated 2026-11-21 · picoGym · By CTFdojo · ⏱ ...
𝕏 Share
TL;DR

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.

PlatformpicoGym (picoCTF 2022)
Verified againstir0nstone's writeup
CategoryCryptography
DifficultyBeginner
Tools python3 quipqiup

Challenge description

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

Hint 1

Read the very first line of the file carefully.

Hint 2

It's a 26-letter alphabet: the key. Map each letter back through it.

Step 1 — Look at the first line

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.

Step 2 — Reverse the mapping in Python

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.

Step 3 — Without the key: frequency analysis

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.

🚩 picoCTF{flag intentionally hidden}

The flag is deliberately hidden — follow the method, you've earned it. 💪

Key takeaways

Always read the whole file before attacking a cipher — sometimes the key is right there:

Resources

New to CTFs? Start here: beginner's guide to CTFs — what a CTF is, the categories, the tools and a step-by-step plan.

CTFdojo
CTFdojo
Community of ethical hackers writing beginner-friendly CTF writeups and guides.

Got a question or a different approach?

Discuss this writeup with the community on the CTFdojo Discord.

Join the Discord →