challenge.py
ciphertext.bin

Simply Permutation Network

Can you remind me what the S in SPN stands for?

solve this crypto ctf

Dr.Binary
read_file
run_sandbox

Classic setup: a "Substitution–Permutation Network" where someone forgot the S. Let me confirm the structure and exploit it.

write_file
run_sandbox

The 5 leading zero bytes are just big-endian padding — the message is 59 bytes, so the flag is 31 bytes and flag[4:27] = "y0u_4ls0_n33d_sub5t17ut". Since m2 = m2_comp ^ flag4, the 4 unknown leading bytes of the flag also unlock the 4 unknown trailing bytes exactly:

run_sandbox

Neither guess fits. The tail is byte-wise V ^ flag4 (V = low 32 bits of m2_comp), and both sides are printable ASCII — that's a strong joint constraint. Let me enumerate all consistent pairs:

run_sandbox

The algebra is exact, so the free bits are provably only the flag's first and last 4 bytes (64 unknown bits total — information-theoretically unrecoverable from ciphertext alone). Let me verify the attack end-to-end against the reference cipher, then enumerate the printable-consistent completions:

write_file
run_sandbox

Fixing the two bugs in my validation harness (flag-length construction and the rindex guard):

edit_file
edit_file
run_sandbox

The end-to-end validation now passes: F=31, msglen=59 (matching the 5 pad bytes we observed) recovers the middle exactly, confirming the unknown bits are precisely flag[0:4] and flag[27:31]. Now let me pin those down — note the tail must complete the word: ...sub5t17ut + 10n} = "substitution", which forces the prefix via X = T ^ V:

run_sandbox

tail "10n}" => prefix "BIU{" — Bar-Ilan University's CTF format. Let me finalize the solve and run an independent sanity check on whether the effective-key map could refute a wrong guess:

write_file
run_sandbox

The flag computation is instant (it printed before my buggy print crashed); only the statistics loop timed out. Let me run a faster version plus a web check on the flag format in parallel:

run_sandbox
web_search

The web search found no public writeup (university/private CTF), but the math is closed. Here's the complete solution:

What the S stands for

Substitution — and this cipher doesn't have any. The round function is only xor round key → bit permutation, both GF(2)-affine operations. Expanding the 16 rounds:

C = k₁₆ ⊕ L(k₁₅ ⊕ L(⋯ L(k₀ ⊕ m)⋯))  =  K* ⊕ L¹⁶(m)
K* = k₁₆ ⊕ L(k₁₅) ⊕ L²(k₁₄) ⊕ ⋯ ⊕ L¹⁶(k₀)

The whole 16-round "SPN" with a 256-bit key collapses to a one-time pad with an effective key K* (I verified this identity against the challenge's own encrypt_block in solve.py's self-test). The LCG round keys and 2²⁵⁶ keyspace are irrelevant.

Attack (final_solve.py)

  1. Known plaintext: block 1 starts with "This is the encrypted flag: " → K* = C₁ ⊕ L¹⁶(m₁) known except the 32 bits contributed by the flag's first 4 bytes.
  2. Decrypt block 2 (the flag block): m₂ = L⁻¹⁶(C₂ ⊕ K*). Since L⁻¹⁶∘L¹⁶ = id, the unknown bits land exactly on m₂'s low 32 bits — everything else is exact: flag[4:27] = y0u_4ls0_n33d_sub5t17ut (the 5 leading \x00 are big-endian padding → message is 59 bytes, flag is 31 bytes).
  3. Tie the two unknown groups together: m₂ = m₂_comp ⊕ flag[0:4], so tail = head ⊕ V with V = 73793b06. I verified statistically (20k random keys, all 32 free bits balanced ~0.5, all pairs distinct) that the ciphertext imposes no further constraint — the 8 unknown chars are information-theoretically lost and must be completed semantically.
  4. Completion: ...sub5t17ut + 10n} = "substitution", which forces head = tail ⊕ V = BIU{ (Bar-Ilan University CTF format). Sanity check: 4 + 23 + 4 = 31 chars → 59-byte message → exactly the 5 padding bytes observed. ✓

Flag

BIU{y0u_4ls0_n33d_sub5t17ut10n}

Artifacts: solve.py (affine decomposition + validation), enumerate_tail.py (consistency enumeration), final_solve.py (final solve).

write a write up.md of only how to solve the challenge pleasae no special charactres well explained like explaining the tought to someone that doesnt know the knowledge

Dr.Binary
write_file
run_sandbox

Done. The writeup is at writeup.md — pure ASCII, no special characters (verified: 0 non-ASCII bytes).

It walks a reader with zero background through the whole solve:

  1. What an SPN is and why the missing S-box matters — explained via "flip one input bit, watch what happens to the output" intuition for XOR vs. an S-box.
  2. The collapse: since every round is only XOR + bit moving, the 16 rounds unroll into C = Kstar XOR L^16(m) — a one-time pad in disguise, with Kstar being the round keys piled up through the permutation.
  3. Known plaintext: the 28-byte "This is the encrypted flag: " prefix gives Kstar except 32 bits, whose positions are tracked precisely.
  4. Decrypting block 2: the inverse permutation sends those 32 unknown bits back to exactly the last 4 bytes, so the middle y0u_4ls0_n33d_sub5t17ut decrypts perfectly, and the 5 zero bytes reveal the flag length (31 bytes).
  5. Closing the gaps: why the ciphertext alone can't give the first/last 4 bytes (any guess has a consistent key — backed by the 20k-key statistical check), then the two-step completion: finish sub5t17ut with 10n}, and XOR the tail with the mask V to force the prefix BIU{.

Ends with the final flag BIU{y0u_4ls0_n33d_sub5t17ut10n} and a one-line lesson.