convertme.py Beginner picoMini 2022 Solution

Published: April 2, 2026

Description

Run the Python script - it asks you to convert a random decimal number to binary.

Download convertme.py from the challenge page.

Solution

Want to try it yourself first?

The guided walkthrough reveals hints one step at a time.

Walk me through it
New to Python scripting for CTF? Python for CTF: Essential Scripting Techniques covers binary data handling, encoding, sockets, and pwntools - all patterns you will use throughout CTF competitions.
  1. Step 1
    Run the script
    Observation
    I noticed the challenge provided a Python script named convertme.py and described a conversion task, which suggested running it first to see what input it expects and what number it generates.
    Execute the script. It generates a random decimal number and asks you to type its binary representation.
    python
    python3 convertme.py
    What didn't work first

    Tried: Running the script with python instead of python3

    On systems where python points to Python 2, the script may fail with a syntax error or behave differently because print is a statement in Python 2, not a function. The challenge uses Python 3 syntax, so python3 is the correct interpreter to invoke.

    Tried: Opening convertme.py in a text editor to find a hardcoded answer

    The script generates a random decimal number each run using a random number generator, so no hardcoded answer exists in the source. Reading the file reveals the generation logic but not the answer - you must actually perform the conversion for whichever number the script produces.

    Learn more

    Binary (base-2) is the foundational number system of all digital computing. Every value a computer stores or processes is ultimately represented as a sequence of 0s and 1s - each called a bit. Understanding binary is essential for understanding how computers handle integers, memory addresses, network masks, and file permissions.

    The script generates a random decimal number so you cannot simply memorize the answer - you need to perform the conversion yourself or use a tool. This is intentional: the challenge teaches the concept rather than a specific value.

  2. Step 2
    Convert the decimal number to binary
    Observation
    I noticed the script prompted for the binary representation of a randomly generated decimal number, which suggested using Python's built-in bin() function to perform the conversion quickly and accurately without manual long division.
    Use Python's built-in bin() function, which returns a string prefixed with '0b'. Slice off the prefix with [2:] to get just the binary digits.
    python
    python3 -c "print(bin(25)[2:])"

    Expected output

    11001
    What didn't work first

    Tried: Typing the bin() output including the 0b prefix into the script prompt

    The script expects only the raw binary digit string such as 11001, not the Python literal form 0b11001. Submitting with the prefix causes the answer check to fail and the script reports an incorrect answer. The [2:] slice is what removes the prefix before entering the value.

    Tried: Using hex(n) or oct(n) instead of bin(n) to convert the number

    hex() returns a hexadecimal string (e.g., 0x19) and oct() returns an octal string (e.g., 0o31), neither of which is the binary representation the script expects. The prompt specifically asks for binary - base-2 digits only - so bin() is the correct built-in to use.

    Learn more

    Python's bin() built-in converts any integer to its binary string representation. The return value is always prefixed with "0b" - Python's notation for binary literals - so slicing with [2:] strips that prefix and leaves only the digit string (e.g., "11001" for 25).

    The manual conversion algorithm works by repeatedly dividing the number by 2 and recording the remainders from bottom to top. For example, 25 ÷ 2 = 12 remainder 1, 12 ÷ 2 = 6 remainder 0, 6 ÷ 2 = 3 remainder 0, 3 ÷ 2 = 1 remainder 1, 1 ÷ 2 = 0 remainder 1 - reading the remainders upward gives 11001.

    Python also provides hex() and oct() for hexadecimal and octal conversions, both using the same [2:] prefix-stripping trick. These number bases appear constantly in CTF challenges: hex in memory dumps and shellcode, octal in Unix file permissions.

  3. Step 3
    Enter the binary value
    Observation
    I noticed the script was waiting for input after displaying the decimal number, which indicated that typing the computed binary string into the prompt would trigger the flag to be printed if the answer was correct.
    Type the binary answer into the script prompt. If correct, the script prints the flag.
    Learn more

    This step reinforces that the flag is gated behind a correct answer - a common CTF pattern where knowledge or computation is required before a secret is revealed. In real systems, this mirrors challenge-response authentication: the server poses a problem, and only a client with the correct knowledge can respond.

    For harder variants of this type of challenge (where the server gives you very little time to respond), you would automate the response using pwntools: receive the number, compute bin(n)[2:] programmatically, and send it back - all within milliseconds. Building that habit now prepares you for timed challenges later.

Interactive tools
  • Base64 & Base32 DecoderDecode Base64 and Base32 strings with auto-detection. Multi-layer mode unwraps nested encodings automatically.
  • Recipe ChainStack decoders into a pipeline: Base64, hex, ROT, XOR, Morse, URL, Atbash, Vigenère, and more. Magic mode auto-discovers the chain. Bookmark the URL to save it.
  • Number Base ConverterConvert numbers between binary, octal, decimal, and hexadecimal instantly. Enter any value and see all four bases update in real time.
Alternate Solution

No terminal? Use the Number Base Converter on this site - enter the decimal number and it instantly shows the binary equivalent, as well as hex and octal, without any coding.

Flag

Reveal flag

picoCTF{4ll_y0ur_b4535_...}

Binary (base-2) has only digits 0 and 1; each position is a power of 2. Python's bin() prefixes with '0b' - slicing [2:] removes it to give just the binary digits.

Key takeaway

Computers represent every integer, address, and instruction in binary because transistors have exactly two stable states. Number base conversions between binary, decimal, octal, and hex appear throughout CTF challenges and real-world work: memory dumps are shown in hex, Unix file permissions in octal, and network subnet masks in binary. Python's bin(), hex(), and oct() built-ins handle these conversions instantly, and recognizing which base a number is in from its prefix (0b, 0x, 0o) or digit set is a skill used in reverse engineering, cryptography, and forensics alike.

Related reading

Want more Beginner picoMini 2022 writeups?

Useful tools for General Skills

What to try next