628 words
3 minutes
πŸ” PicoGym - transposition-trial

πŸ“‚ Download challenge file.

Description: Our data got corrupted on the way here. Luckily, nothing got replaced, but every block of 3 got scrambled around! The first word seems to be three letters long, maybe you can use that to recover the rest of the message.
Difficulty: Medium
Author: Will Hong

Summary#

In this challenge, we are given a corrupted message where every group of three characters has been scrambled, but no characters were lost or replaced. By leveraging the hint that the first word is three letters long, we can identify the scrambling pattern and apply it consistently across the entire ciphertext to recover the flag.

This is a classic block transposition cipher.

Analysis#

We are provided with a file named message.txt:

Terminal window
$ file message.txt
message.txt: ASCII text, with no line terminators

Its content:

$ cat message.txt
heTfl g as iicpCTo{7F4NRP051N5_16_35P3X51N3_V091B0AE}2

The challenge name (transposition-trial) and the description strongly suggest a transposition cipher, where characters are rearranged but not modified.

To confirm, we can use dCode’s Cipher Identifier.

alt text

Yep, I was right, it’s Transposition Cipher.

What is Transposition Cipher?#

A transposition cipher encrypts a message by rearranging the order of characters according to a fixed pattern or key, without changing the characters themselves.
Key properties:

  • No substitution occurs
  • Character frequency remains the same
  • Decryption requires discovering the correct permutation

Encryption#

In this challenge, the permutation is applied per block of 3 characters. The plaintext is divided into blocks of 3 characters, and each block is scrambled according to a fixed pattern.

For example, if we have a block abc and the pattern is a specific permutation, the encrypted block might be cab or bac depending on the pattern used.

Decryption#

To decrypt, we need to:

  1. Identify the correct permutation pattern used for scrambling
  2. Reverse that pattern (apply the inverse permutation) to each block of 3 characters
  3. Concatenate the decrypted blocks to recover the plaintext

The hint tells us the first word is three letters long, which is likely β€œThe”. This gives us a known plaintext-ciphertext pair:

  • Ciphertext: heT
  • Plaintext: The

From this, we can determine the permutation pattern.

Solution#

Step 1: Determine the permutation pattern#

The first block heT should decrypt to The. Let’s map the positions:

The plaintext is The, encrypted as heT. To encrypt:

  • T (index 0) β†’ position 2 (becomes T at the end)
  • h (index 1) β†’ position 0 (becomes h at the start)
  • e (index 2) β†’ position 1 (becomes e in middle)

So the encryption pattern is: [1, 2, 0] (take char at 1, then 2, then 0 of original)

To decrypt, we need the inverse permutation. If encryption uses pattern [1, 2, 0], decryption uses [2, 0, 1]:

  • Encrypted position 0 β†’ goes to plaintext position 2
  • Encrypted position 1 β†’ goes to plaintext position 0
  • Encrypted position 2 β†’ goes to plaintext position 1

Step 2: Implement the decryption#

Let’s verify with the first block heT:

  • Apply pattern [2, 0, 1]:
    • [2]: heT[2] = T β†’ position 0
    • [0]: heT[0] = h β†’ position 1
    • [1]: heT[1] = e β†’ position 2
    • Result: The βœ“

Here’s a Python solution:

ciphertext = "heTfl g as iicpCTo{7F4NRP051N5_16_35P3X51N3_V091B0AE}2"
# inverse permutation of [1, 2, 0]
perm = [2, 0, 1]
plaintext = ""
for i in range(0, len(ciphertext), 3):
block = ciphertext[i:i+3]
if len(block) == 3:
plaintext += ''.join(block[p] for p in perm)
else:
plaintext += block # handle leftover chars if any
print(plaintext)

Step 3: Decrypt the entire message#

Running the decryption function on the ciphertext :

picoCTF{7R4N5P051N6_15_3XP3N51V3_109AB02E}

⚑ Raikiri

πŸŽ‰ Flag pwned!

Terminal window
$ python solve.py
The flag is picoCTF{7R4N5P051N6_15_3XP3N51V3_109AB02E}
πŸ’‘ TL;DR / Lesson Learned
  1. Known plaintext attack: The hint that the first word is three letters (likely β€œThe”) was crucial for determining the permutation pattern.
  2. Block transposition with fixed pattern: Once we identified the pattern from one block, we could apply it consistently to all other blocks.
  3. No character substitution: This confirms it’s purely a transposition, not a substitution cipher - all characters remain unchanged, just reordered within each 3-character block.
  4. Inverse permutation: To decrypt, we need to apply the mathematical inverse of the encryption permutation to reverse the scrambling.