Description: I found the flag, but my brother wrote a program to encrypt all his text files. He has a spelling quiz study guide too, but I donβt know if that helps.
Difficulty: Medium
Author: BrownieInMotion
Summary
Itβs an encryption of all text files using a substitution cipher. We have three things to work with: the encryption program, an encrypted flag, and an encrypted spelling quiz study guide. The key advantage is that the study guide and flag were encrypted using the same cipher key. By analyzing the encrypted study guide with frequency analysis, we can discover the substitution mapping and decrypt the hidden flag.
Analysis
Challenge Files
The challenge provides a public.zip file containing three items:
encrypt.py β The encryption programflag.txt β The encrypted flagstudy-guide.txt β Encrypted spelling quiz wordsThe Encrypted Flag
Looking at the encrypted flag:
$ cat flag.txtbrcfxba_vfr_mid_hosbrm_iprc_exa_hoav_vwcrmThis looks like random letters - but itβs actually a substitution cipher.
Understanding the Encryption
Hereβs the encryption program:
import randomimport os
files = [ os.path.join(path, file) for path, dirs, files in os.walk('.') for file in files if file.split('.')[-1] == 'txt']
alphabet = list('abcdefghijklmnopqrstuvwxyz')random.shuffle(shuffled := alphabet[:])dictionary = dict(zip(alphabet, shuffled))
for filename in files: text = open(filename, 'r').read() encrypted = ''.join([ dictionary[c] if c in dictionary else c for c in text ]) open(filename, 'w').write(encrypted)What this does:
- Finds all
.txtfiles in the directory - Creates a shuffled alphabet (randomized order)
- Creates a dictionary mapping original letters to shuffled letters
- For each file, replaces every letter using the dictionary
- Saves the encrypted text back to the file
Key insight: The same shuffled alphabet is used to encrypt ALL files, including the study guide and flag!
The Study Guide
The encrypted study guide contains words from a spelling quiz:
$ head study-guide.txtgocnfwnwtrsxlyrxaicdcrrtfrxcvuxbvwavcqlwvicwtiwmpwtmwnxvicqavingciisaylwtmrcawxmwaxdcrrxuwlwvqyciflwnfIdentifying the Cipher Type
Using cipher identification tools like dcode.fr, these encrypted words are strongly identified as Monoalphabetic Substitution.

Solution
How Frequency Analysis Works
In English, certain letters appear more frequently than others:
- βeβ appears most often (~12.7%)
- βtβ, βaβ, βoβ, βiβ are also very common
- βzβ, βqβ, βxβ are rare
If we encrypt English text, the most common encrypted letter should correspond to βeβ, the second most common to βtβ, etc.
Cracking the Cipher
- Use frequency analysis tools on the encrypted texts
- Upload to dcode.fr Monoalphabetic Substitution
- Feed it the encrypted study guide - the tool analyzes letter frequencies
- The tool outputs the original alphabet mapping
- Use the mapping to decrypt the flag
Results
After running frequency analysis on the encrypted study guide and flag:

The decrypted flag:
PERHAPS_THE_DOG_JUMPED_OVER_WAS_JUST_TIREDβ‘ Raikiriπ Flag pwned!
Wrap it as: picoCTF{PERHAPS_THE_DOG_JUMPED_OVER_WAS_JUST_TIRED}
π‘ TL;DR / Lesson Learnedβ Substitution Cipher - Each letter maps to exactly one other letter
β Monoalphabetic - The mapping never changes (unlike polyalphabetic ciphers)
β Frequency Analysis - Using letter frequency patterns to break encryption
β Ciphertext-only attack - We donβt need the key, just encrypted text and patterns
β Using known plaintext - The spelling quiz study guide is likely real English words!