← Back to Writeups
CUSTOMEasyCrypto

Permute — Permutation Cipher

XESXOR9/10/20261 min read
#crypto#custom#easy#block_transposition#permutation_bruteforce

Permute — Permutation Cipher

Platform: spbctf | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-03-08 | Status: Solved Techniques: block_transposition, permutation_bruteforce

Summary

Task: Decrypt a permutation cipher with 4-letter blocks. Solution: Bruteforce all 24 permutations of block size 4, find the one that produces readable text.

Permute — Crypto Kids 2.0

Description

It's permutation cipher. Decrypt: hT elfgaf rot ih satksi :sD 33_pnI1sEDy_U0c_yrRCcYYrtp.0. There are 4 letters in a block.

Analysis

Permutation cipher with block size 4. The text is split into 4-character blocks, and within each block the letters are rearranged according to a specific permutation. We need to find the correct permutation out of 4! = 24 possibilities.

Solution

python
#!/usr/bin/env python3
from itertools import permutations

ciphertext = "hT elfgaf rot ih satksi :sD 33_pnI1sEDy_U0c_yrRCcYYrtp.0"
block_size = 4
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Split into blocks
blocks = [ciphertext[i:i+block_size] for i in range(0, len(ciphertext), block_size)]

# Try all permutations
for perm in permutations(range(block_size)):
    result = ""
    for block in blocks:
        if len(block) == block_size:
            result += ''.join(block[p] for p in perm)
        else:
            result += block
    
    if "flag" in result.lower() or "spbctf" in result.lower():
        print(f"Permutation {perm}: {result}")

# Correct permutation: (1, 0, 3, 2) — swap pairs
# Output: The flag for this task is: REDACTED.

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Permutation (1, 0, 3, 2) means: swap the 1st and 2nd characters, and also the 3rd and 4th. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍