Quantum Scrambler picoCTF 2025 Solution

Published: April 2, 2025

Description

"Quantum Scrambler" is nothing more than a deterministic shuffle of a list of hex bytes. Capture the remote output, re-run the loops in reverse, and you recover the original flag.

Connect with nc and save the shuffled output to a file (the server only scrambles the list and prints it).

Download quantum_scrambler.py so you can study the scramble function and confirm no actual encryption took place.

Sanity-check the saved blob: the last line should be a nested Python list literal that looks like [[['0x70', '0x69'], ['0x63', '0x6f']], [...]], not raw binary. Earlier lines are the server's banner and prompts, which is why the solver takes only splitlines()[-1].

bash
nc verbal-sleep.picoctf.net <PORT_FROM_INSTANCE> > result
bash
wget https://challenge-files.picoctf.net/c_verbal_sleep/27d1d27147deac5835e1ef9633cf1858c89bf32b14e2f4fbac72b6ca093f6d27/quantum_scrambler.py
bash
tail -1 result
Reading the "encryption" source and replaying it backwards is a recurring CTF pattern. Python for CTF covers the parsing primitives, and the broader CTF Encodings cheatsheet catalogues the cosmetic transformations like this one that masquerade as crypto.
  1. Step 1Understand the scramble routine
    The provided code repeatedly pops elements and appends prefixes, but never modifies the underlying data. It simply reorders sublists, meaning the plaintext bytes are still present.
    Learn more

    Security through obscurity is the antipattern this challenge demonstrates. The "Quantum Scrambler" name sounds sophisticated, but examining the source reveals it is purely a permutation - a reordering of data with no cryptographic key, no mixing of values, and no information loss. Every original byte is present in the output; only their arrangement changed.

    True encryption transforms data in a way that is computationally infeasible to reverse without the key. Permutation-only schemes fail this test because the number of possible arrangements is finite (factorial of input length), and more importantly, in this challenge the permutation algorithm is deterministic and provided in source. Anyone who reads quantum_scrambler.py can reverse it instantly.

    This is a common mistake in amateur cryptography: building elaborate pipelines of bit shifts, rotations, and shuffles that look complex but lack true randomness or key material. Claude Shannon's formal definition of confusion (substitution that hides the relationship between key and ciphertext) and diffusion (spreading plaintext influence across many ciphertext bits) are the properties that distinguish real ciphers from shuffles like this one.

  2. Step 2Iterate through the nested lists
    Parse the saved result with ast.literal_eval (the server prints a banner before the data, so take only the final line via splitlines()[-1]). The walk function below recursively descends into every sublist and emits each hex string in document order, then chr(int(c, 16)) decodes the byte. This rebuilds the original byte sequence directly - simpler than partial first/last extraction because the scramble's nesting has already preserved order across the full tree.
    python
    # Use ast.literal_eval, NOT eval (server output is untrusted):
    python3 - <<'PY'
    import ast
    with open('result') as f:
        data = ast.literal_eval(f.read().strip().splitlines()[-1])
    out = []
    def walk(node):
        if isinstance(node, str):
            out.append(node)
        else:
            for child in node:
                walk(child)
    # Sanity test: walk([[['0x41']], [['0x42']]]) should produce 'AB'
    test = []
    def _t(n):
        if isinstance(n, str): test.append(n)
        else:
            for c in n: _t(c)
    _t([[['0x41']], [['0x42']]])
    assert ''.join(chr(int(c, 16)) for c in test) == 'AB', 'walk() broken'
    walk(data)
    print(''.join(chr(int(c, 16)) for c in out))
    PY
    Learn more

    Using Python's eval() to parse the output is a quick CTF trick because the server's output is a valid Python literal (a nested list of strings). In production code, eval is dangerous - it executes arbitrary Python, so it should never be used on untrusted input. The safe alternative is ast.literal_eval(), which parses only Python literals (strings, numbers, lists, dicts, tuples) without executing arbitrary expressions.

    The nested list structure the scrambler produces is an artifact of repeated prepend operations - each step wraps the current list as an element inside a new outer list. Reversing this by walking the nesting depth and collecting elements in the correct order is a tree traversal problem. Understanding the forward algorithm precisely enough to invert it is the core skill tested here.

    In real reverse engineering, you often encounter proprietary serialization formats or obfuscated data structures that must be parsed before the payload can be analyzed. Fluency with Python for rapid data structure manipulation - list comprehensions, slicing, zip, map - is invaluable for quickly prototyping parsers and decoders during CTF competitions.

  3. Step 3Decode to ASCII
    The same chr(int(c, 16)) line at the bottom of the script is the hex-to-ASCII conversion - each chunk like '0x70' becomes 'p'. Joining them prints the picoCTF flag; nothing further to do.
    Learn more

    Hexadecimal representation of bytes is ubiquitous in low-level security work. Each byte (0 to 255) maps to a two-digit hex value (0x00 to 0xff). The int(chunk[2:], 16) idiom strips the 0x prefix and converts the remaining hex digits to an integer in base 16. chr() then maps the integer to its Unicode character; for values 32 to 126 (printable ASCII) this is the familiar character set.

    The inverse operations are equally important: hex(ord('A')) gives 0x41, and '{:02x}'.format(65) gives '41'. These conversions appear constantly in cryptography, binary exploitation, and network protocol analysis. Python's bytes type and its .hex() / bytes.fromhex() methods are often more ergonomic for bulk conversions than character-by-character loops.

    The lesson here is that adding visual complexity to data (wrapping bytes in 0x-prefixed hex strings and nesting them in lists) does not add security. Any transformation that is purely cosmetic and reversible without a key provides zero cryptographic protection. Recognizing "fake encryption" quickly is a valuable CTF skill that also translates to evaluating real-world security claims about data "obfuscation" products.

Alternate Solution

Once you have reassembled the hex byte sequence, use the Binary to Hex tool on this site to convert the hex chunks to ASCII characters one by one - or paste the entire hex string to decode the flag without writing any additional Python.

Flag

picoCTF{python_is_weird9ece...}

Any faithful translation of the scramble loop works; the key insight is that nothing was encrypted, only permuted.

Want more picoCTF 2025 writeups?

Useful tools for Reverse Engineering

Related reading

What to try next