basic-mod2

Published: July 20, 2023Updated: December 9, 2025

Description

The follow-up to basic-mod1 swaps the modulus to 41 and asks for the modular inverse of each value before mapping 1–26 to letters, 27–36 to digits, and 37 to underscore.

Convert the provided numbers into a Python list so you can iterate through them easily.

For each entry compute the modular inverse `pow(n, -1, 41)` (Python’s built-in handles it) and subtract 1 to use zero-based indexing.

Translate the resulting values into the alphabet/digit/underscore character set and assemble the flag.

wget https://artifacts.picoctf.net/c/180/message.txt
cat message.txt
cat message.txt | sed -e "s/^/[/" | sed 's/ *$//' | sed -e "s/$/]/" | sed -e "s/ /, /g"
python3 mod2.py

Solution

  1. Step 1Reuse the parsing trick
    The same sed pipeline from basic-mod1 turns the raw numbers into a Python-friendly array, letting you focus on the math instead of text processing.
  2. Step 2Compute modular inverses
    Python’s `pow(value, -1, 41)` returns the multiplicative inverse modulo 41. Because the alphabet in this challenge is 1-indexed, subtract 1 before indexing into `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_`.
  3. Step 3Build the string
    Append each character to a string prefixed with `picoCTF{` and close the brace to finalize the decoded message.

Flag

picoCTF{1NV3R53LY_H4RD_8A05...}

Modular inverses rarely show up in intro problems, but Python’s `pow` handles them without extra libraries.