Skip to main content

convertme.py Beginner picoMini 2022 Solution

A beginner Python challenge testing your ability to convert numbers between different bases.

Published: April 2, 2026Updated: August 13, 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 1Run the script
    Observation
    The challenge gives a Python script named convertme.py and describes a conversion task. Running it first shows what input it wants 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 at Python 2, the script may fail with a syntax error or behave differently, because print is a statement there rather than a function. The challenge uses Python 3 syntax, so invoke python3.

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

    The script generates a new random decimal each run, so no hardcoded answer exists in the source. Reading the file shows the generation logic but not the answer; you have to convert whichever number the script actually 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 2Convert the decimal number to binary
    Observation
    The script asks for the binary representation of a randomly generated decimal number. Python's bin() does that conversion instantly, with no long division by hand.
    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 wants the raw binary digit string, 11001, not the Python literal 0b11001. Submit it with the prefix and the check fails and reports an incorrect answer. The [2:] slice is what strips the prefix before you enter the value.

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

    hex() returns a hexadecimal string like 0x19 and oct() returns an octal string like 0o31, and neither is what the script asked for. The prompt wants binary, base-2 digits only, so bin() is the 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 3Enter the binary value
    Observation
    The script is waiting for input after printing the decimal number. Typing the computed binary string at the prompt triggers the flag if the answer is right.
    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
  • Strings ExtractorPull printable text from any binary, library, or image. ASCII and UTF-16 detection, configurable minimum length, flag-like highlight, no command line needed.
  • Regex TesterTest regular expressions against a string with live match highlighting, flag toggles, and common CTF pattern shortcuts.
  • Base64 & Base32 DecoderDecode Base64 and Base32 strings with auto-detection. Multi-layer mode unwraps nested encodings automatically.
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. Base conversions between binary, decimal, octal, and hex run through CTFs and real work alike: memory dumps come in hex, Unix permissions in octal, subnet masks in binary. Python's bin(), hex(), and oct() handle the conversions instantly, and telling which base a number is in from its prefix (0b, 0x, 0o) or digit set is a skill used across reverse engineering, cryptography, and forensics.

Related reading

Useful tools for General Skills

Where to go next