DAMCTF 2025 · Crypto
Hidden Orongutang — DAMCTF 2025
2 min read · solved 2025-05-10
| Event | DAMCTF 2025 |
| Category | Cryptography |
| Challenge | Hidden Orongutang |
| Author's note | "Simple Chessography substitution cipher" |
| Files | message.txt, 2025-05-09_Alice_vs_Bob.pgn |
| Solved by | Joker (Ridjan Xhika) |
TL;DR
The plaintext is written onto a chessboard, one character per square. Every move of a real chess game then swaps the characters on its source and destination squares. Replay the game's moves backwards on the ciphertext board and the flag falls out.
dam{ch3ss0graphy_1s_fun_but_did_y0u_f1nd_th3_or4ngutan?}
The files
message.txt is 64 characters — exactly one chessboard — and looks like shuffled flag:
sudsn __yast n __fd{3d n___pfhigug1trr}bay t_1 0?udn oh30uhmac4
You can already spot d{, } and ? in there. All the right letters are present, just in the wrong places.
2025-05-09_Alice_vs_Bob.pgn is a normal chess game in PGN notation (Alice vs Bob, 0-1), 91 full moves / 182 half-moves, opening with:
1. c4 Nf6 2. b4 e5 3. a3 c5 4. b5 a6 ...
2. b4 is the Orangutan (Sokolsky) Opening — that's the joke in the challenge name.
Analysis
It's a transposition, not a substitution
Despite the description, no letter is ever changed: the ciphertext has exactly the same characters as the flag, just moved. So this is a transposition cipher where the permutation comes from the chess game.
Laying the text on the board
Filling the board row by row from a8 to h1 (top-left to bottom-right from White's side) gives this ciphertext board:
8 │ s u d s n _ _
7 │ y a s t n
6 │ _ _ f d { 3 d
5 │ n _ _ _ p f h i
4 │ g u g 1 t r r }
3 │ b a y t _ 1
2 │ 0 ? u d n o h
1 │ 3 0 u h m a c 4
└────────────────
a b c d e f g h
What each move does
Each half-move like c2c4 (from square → to square) swaps the characters on those two squares. Captures, castling and promotions don't need special handling: a move is still just "from" and "to".
Encryption = apply all 182 swaps in order. Because a swap is its own inverse, decryption = apply the same swaps in reverse order. Doing 182 swaps by hand is error-prone, so this is a job for a script.
Solution
python-chess parses the PGN and gives each move in UCI form (c2c4, g8f6, …), which is exactly the from/to pair we need.
import chess.pgn
COLS = "abcdefgh"
def load_board(text):
# a8 -> h1, row by row
grid = {}
for i, ch in enumerate(text.ljust(64)[:64]):
rank = 8 - i // 8
grid[f"{COLS[i % 8]}{rank}"] = ch
return grid
def board_to_text(grid):
return "".join(grid[f"{c}{r}"] for r in range(8, 0, -1) for c in COLS)
game = chess.pgn.read_game(open("2025-05-09_Alice_vs_Bob.pgn"))
moves = [m.uci()[:4] for m in game.mainline_moves()] # 182 half-moves
grid = load_board(open("message.txt").read())
for mv in reversed(moves): # undo the game
a, b = mv[:2], mv[2:]
grid[a], grid[b] = grid[b], grid[a]
print(board_to_text(grid))
After undoing every move, the board reads:
8 │ d a m { c h 3 s
7 │ s 0 g r a p h y
6 │ _ 1 s _ f u n _
5 │ b u t _ d i d _
4 │ y 0 u _ f 1 n d
3 │ _ t h 3 _ o r 4
2 │ n g u t a n ? }
1 │
Flag
dam{ch3ss0graphy_1s_fun_but_did_y0u_f1nd_th3_or4ngutan?}
Takeaways
- Check the letter counts first. Same characters in a different order means transposition, whatever the description says.
- Look for the key in the "extra" file. The PGN wasn't decoration; it was the key.
- Swaps are self-inverse. Reversing the move list is the whole decryption.
- Use
python-chess: hand-parsing PGN (castling, captures, disambiguation) is where bugs hide.
Original solve script: github.com/ridjan-xhika/damctf