Codebook

Published: April 2, 2026

Description

Run code.py using the codebook.txt file to get the flag.

Download both code.py and codebook.txt from the challenge page.

Place both files in the same directory before running.

Solution

  1. Step 1Run the script with codebook.txt present
    Execute code.py from the directory that also contains codebook.txt. The script reads the codebook, decodes the flag, and prints it automatically.
    python3 code.py
    Learn more

    A codebook is a lookup table that maps one set of symbols to another. In this challenge, code.py reads codebook.txt to translate encoded values back into the readable flag. This pattern mirrors historical encryption methods like the Vigenere cipher or one-time pads, where a separate key document was required for decryption.

    The critical lesson here is about relative file paths. When Python opens a file with open("codebook.txt"), it looks in the current working directory -- whichever directory your terminal session is in when you run the command, not necessarily where the script lives. Running the script from the wrong directory causes a FileNotFoundError.

    In real-world development and security contexts, this dependency between files is usually documented or handled programmatically (e.g., using os.path.dirname(__file__) to locate the codebook relative to the script). Always check whether a script expects companion files and confirm your working directory before running.

Flag

picoCTF{...}

The script requires both files to be in the same directory -- a common pitfall for beginners who only download one file or run the script from a different working directory.

More General Skills