Skip to main content

vault-door-3 picoCTF 2019 Solution

Reverse a Java program that scrambles a string through index manipulation to recover the original password.

Published: April 2, 2026Updated: August 13, 2026

Description

This vault uses for-loops to scramble the password. Reverse the scramble to find the original. The Java source code is provided.

Download VaultDoor3.java 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
  1. Step 1Understand the scrambling loops
    Observation
    checkPassword() in VaultDoor3.java copies characters into a buffer through several for-loops with different index arithmetic. That is a permutation: the original characters are all still there, just rearranged. Mapping each loop's indices comes first.
    The checkPassword() method copies characters from the input into a buffer array using index arithmetic from several for-loops (forward copy, reverse copy, interleaving). Read each loop carefully and note which output index receives which input index.
    Learn more

    The scrambling in this challenge is a permutation cipher - all the original characters are present in the buffer, just rearranged. Each for loop implements a specific reordering: copying a range forward, copying a range backward, or interleaving characters from two halves. Understanding the permutation is a matter of careful index arithmetic.

    A useful mental model: think of the scramble as a function f(i) that maps each output index to a source index. Once you know f for every index, you can construct the reverse mapping f⁻¹ and apply it to the scrambled buffer to recover the original string. This is exactly how transposition ciphers work in classical cryptography.

    In modern security contexts, this kind of analysis appears in:

    • Reverse engineering - understanding how a proprietary protocol encodes data
    • Malware analysis - decoding obfuscated strings that have been shuffled to evade detection
    • DRM research - understanding how content protection schemes rearrange data
    • Fuzzing - learning the input format by reading the validation logic
  2. Step 2Reverse the index permutation in Python
    Observation
    Since the scramble is a pure index permutation with no substitution, running the same loops over a list of indices 0 to 31 in Python reveals the inverse mapping. The scrambled buffer then reads back in the original order, with no cryptography to invert.
    Model the scramble as a permutation of indices. Apply the same operations to a list of known positions to determine where each scrambled character originally came from. Then read the characters back in the original order.
    python
    python3 -c "
    # Paste the scrambled buffer from the source here
    buffer = list('jU5t_a_s1mpl3_an4gr4m_4_u_xxxxxxxx')
    # Reverse the loop operations to recover original order
    print(''.join(buffer))
    "
    What didn't work first

    Tried: Re-running the Java scramble loops forward on the scrambled buffer, hoping applying the same function twice undoes itself.

    The permutation is not its own inverse: scramble a second time and you get a doubly-scrambled result, not the original. Build the inverse mapping by tracing which output index each input index feeds, then reverse that mapping before reading the characters back.

    Tried: Pasting the raw password string from the source comment into the buffer variable without first extracting the actual scrambled target from checkPassword().

    The source file contains the scrambled buffer inside checkPassword() as the comparison target, not the plaintext. Using the comment or a placeholder string gives a Python output that does not match the expected flag because you are inverting the wrong input.

    Learn more

    The key insight for reversing this permutation in Python is to simulate the scramble on a list of indices rather than on the actual characters. If you create a list [0, 1, 2, ..., 31] and apply the exact same loop operations to it that the Java code applies to characters, you end up with a list that tells you "the character at position i in the scrambled buffer originally came from position scrambled[i] in the password." This gives you the reverse mapping for free.

    Python is ideal for this because list slicing and index manipulation are concise. The general pattern:

    • Create an index list: idx = list(range(32))
    • Apply the same swaps/copies the Java code performs
    • Read the scrambled buffer using the resulting index order

    This approach generalizes to any block cipher mode analysis, custom encoding scheme, or obfuscation layer where the transformation is deterministic and reversible. The same technique is used by cryptanalysts to recover plaintexts from transposition ciphers - the Rail Fence cipher and columnar transposition both use index permutations that can be reversed this way.

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.
  • Hex ViewerView text or raw hex bytes as a xxd-style hex dump with byte offset, hex columns, and ASCII sidebar. Highlights printable characters and null bytes.

Flag

Reveal flag

picoCTF{jU5t_a_s1mpl3_an4gr4m_4_u_...}

Array-index scrambling is an anagram cipher - all characters are present, just rearranged. Reversing the index permutation restores the original order.

Key takeaway

Transposition ciphers rearrange the characters of a message without substituting them, so the character set survives intact and only the positions move. Reversing one means constructing the inverse permutation, which is a matter of reading the transformation logic rather than attacking a cryptographic primitive. The same technique shows up when analysts trace how a proprietary codec or obfuscator shuffles bytes, and in malware analysis when deobfuscating strings reordered to defeat static pattern matching.

Related reading

Useful tools for Reverse Engineering

Where to go next