Fish CTF Challenge — Solution
Flag
| |
“there may be some issues with this if the collatz conjecture is disproven”
Overview
The challenge provides a Python-based ><> (Fish) esoteric language interpreter and a one-line Fish program (the “fisherator”) that checks user input against a hardcoded large integer.
Algorithm (Forward)
The fisherator transforms the flag in two stages:
Stage 1 — Base-256 Encoding
The flag string is converted into a single big integer by treating its ASCII bytes as a big-endian base-256 number:
$$\text{acc} = \sum_{i=0}^{n} \text{ord}(c_i) \cdot 256^{n-i}$$This is equivalent to int.from_bytes(flag.encode(), 'big').
Stage 2 — Collatz Path Encoding
A modified Collatz sequence is run on acc, encoding each step’s parity into a counter:
| |
The final counter is compared against the hardcoded target number via the n instruction. If they match, the flag is correct.
Reversing
Step 1 — Undo the Collatz Encoding
Starting from counter = TARGET and acc = 1, reverse each step by inspecting the parity of counter:
| |
This recovers the original big integer in 2999 steps.
Step 2 — Decode the Integer
Convert the recovered integer back to bytes (big-endian) to obtain the flag:
| |
Comments