Skip to content
Adam Omar Saleh

TVX CTF 2026 placeholder badge (unofficial)TVX CTF 2026Cryptography

The Fourth Portal

Three “worlds” each publish 16 beacon readings, some of them forged, and a fourth world supplies 8 intact bytes. Rebuilding the lost values opens an AES-GCM vault.

Competition
TVX CTF 2026 placeholder badge (unofficial)TVX CTF 2026
Category
CryptographyMedium · estimated
Source status
Flag recovered locally · platform unverified
Document
PDF edition7 min read

Brief

The challenge

Competition
TVX CTF 2026
Category
Cryptography (platform category: Crypto)
Difficulty
Medium — estimated, not an official rating
Points
100
Solves
77 on the challenge card when captured
Challenge author
Ayham Al-Qaisi
Verification
Flag recovered locally; platform acceptance not documented

Difficulty: Medium (estimated). TVX CTF 2026 did not publish difficulty ratings; the challenge cards show only points and solve counts. The core insight is recognising Reed–Solomon error correction over GF(257), then decoding three codewords with up to four errors each and rebuilding the key exactly as specified. The card showed 77 solves when captured.

01

Overview

An abandoned portal links the Overworld, the Nether, and the End. Then a fourth world answers: the Echo. Its vault is sealed, and someone has forged beacon readings in each of the old dimensions.

Rebuild what the three worlds lost, bring the Echo's piece, and open the vault. The last cartographer left a book on the Echo's lectern.

Challenge page
Challenge page

Three “worlds” each publish 16 beacon readings, some of them forged, and a fourth world supplies 8 intact bytes. Rebuilding the lost values opens an AES-GCM vault.

Solution path in brief

Each world's beacon ledger is a Reed–Solomon codeword: 16 evaluations of a degree-7 polynomial over GF(257), with up to 4 corrupted points. The code's minimum distance is 16 − 8 + 1 = 9, so up to 4 errors can always be corrected and the answer is unique. Decode the three polynomials, interleave their coefficients with the Echo's 8 bytes to get a 32-byte key material, derive the key with HKDF, and decrypt the AES-GCM vault.

Text
beacons → mod 257 → RS-decode (8 coeffs each) → interleave O,N,E,H → HKDF-SHA256 → AES-256-GCM → flag

02

Initial investigation

The investigation started with the file layout and the rules written on the in-game lectern.

The files

Text
overworld/beacons.csv   16 (X, Z) readingsnether/beacons.csv      16 (X, Z) readingsthe_end/beacons.csv     16 (X, Z) readingsthe_echo/core.hex       6e 11 c3 61 9f ee 00 c4the_echo/lectern.txt    the rulesthe_echo/vault.json     HKDF + AES-GCM parameters and ciphertext

lectern.txt explains the setup:

  • Coordinates are reduced to their least nonnegative residue mod 257, so (-1, 258) becomes (256, 1).

  • The honest readings in each world satisfy Z = c0 + c1·X + … + c7·X^7 (mod 257).

  • Up to four readings per world are forged.

  • Each coefficient fits in a byte, and the 32-byte key material is built row by row as O0 N0 E0 H0 O1 N1 E1 H1 ….

03

Tools used

  • Python 3 (itertools, Lagrange interpolation over GF(257))

  • cryptography (HKDF-SHA256, AES-GCM)

04

Step-by-step process

Step 1: Recognising Reed–Solomon

A degree-7 polynomial has 8 unknown coefficients, and each world gives 16 points. Evaluating a polynomial at distinct points is exactly a Reed–Solomon code with parameters [n=16, k=8] over GF(257). Its minimum distance is d = n − k + 1 = 9, so it uniquely corrects ⌊(d−1)/2⌋ = 4 errors. That matches the "up to four forged readings" in the book.

Step 2: Decoding

Berlekamp–Welch would work, but with only C(16, 8) = 12870 subsets per world, brute force is instant:

  1. Pick 8 of the 16 points and run Lagrange interpolation to get a candidate polynomial.

  2. Count how many of the 16 points it fits.

  3. Accept the candidate if it fits at least 12 points (so at most 4 are forged) and every coefficient is below 256.

Any two degree-7 polynomials that each fit 12 of the 16 points would have to share at least 8 of them, which forces them to be the same polynomial. So the first hit is the only one.

WorldCoefficients c0..c7Forged readings (mod 257)
Overworld8e f4 c2 48 5c 80 02 8a(246,197) (156,174) (225,107) (21,185)
Nether93 6c b3 51 a4 06 ea e6(136,221) (26,204) (163,167) (207,119)
The Endc9 3a 0b b1 ab 9d 7b 0a(154,11) (219,60) (218,195) (213,17)
The Echo6e 11 c3 61 9f ee 00 c4(given intact)

Each world had exactly four forged readings.

Step 3: Building the portal frame

Take one byte from each world per row, in the order Overworld, Nether, End, Echo:

Text
ikm = 8e93c96e f46c3a11 c2b30bc3 4851b161 5ca4ab9f 80069dee 02ea7b00 8ae60ac4

Step 4: Opening the vault

From vault.json:

  • HKDF-SHA256, salt 4a06df8e10e1cb1e5c5fd2373f125dda, info TVX:fourth-portal:v1, 32-byte output.

  • AES-256-GCM, nonce 59cea0d35d9d3b98d04739da, AAD echo-vault-v1.

GCM checks its tag before returning plaintext, so a successful decryption proves that every step above was correct:

Text
TVX{th3_3ch0_b1nds_th3_f0ur_w0rlds}

05

Commands and code

Solve script

The full script is in solve.py. The core is:

Python
def decode(pts):    for subset in itertools.combinations(pts, 8):        c = interpolate(list(subset))        good = [p for p in pts if evaluate(c, p[0]) == p[1]]        if len(good) >= 12 and all(v < 256 for v in c):            return bytes(c), [p for p in pts if p not in good]​ikm = bytes(b for i in range(8) for b in (O[i], N[i], E[i], H[i]))key = HKDF(hashes.SHA256(), 32, salt, info).derive(ikm)print(AESGCM(key).decrypt(nonce, ct + tag, aad))

Output:

Text
overworld  coeffs=8ef4c2485c80028a forged=[(246, 197), (156, 174), (225, 107), (21, 185)]nether     coeffs=936cb351a406eae6 forged=[(136, 221), (26, 204), (163, 167), (207, 119)]the_end    coeffs=c93a0bb1ab9d7b0a forged=[(154, 11), (219, 60), (218, 195), (213, 17)]echo       coeffs=6e11c3619fee00c4ikm = 8e93c96ef46c3a11c2b30bc34851b1615ca4ab9f80069dee02ea7b008ae60ac4TVX{th3_3ch0_b1nds_th3_f0ur_w0rlds}

Full source: solve.py

Python
import csv, json, itertoolsfrom cryptography.hazmat.primitives.kdf.hkdf import HKDFfrom cryptography.hazmat.primitives import hashesfrom cryptography.hazmat.primitives.ciphers.aead import AESGCM​P = 257​​def load(world):    with open(f"{world}/beacons.csv") as f:        rows = list(csv.DictReader(f))    return [(int(r["X"]) % P, int(r["Z"]) % P) for r in rows]​​def polymul(a, b):    out = [0] * (len(a) + len(b) - 1)    for i, x in enumerate(a):        for j, y in enumerate(b):            out[i + j] = (out[i + j] + x * y) % P    return out​​def interpolate(pts):    coeffs = [0] * len(pts)    for i, (xi, yi) in enumerate(pts):        num, den = [1], 1        for j, (xj, _) in enumerate(pts):            if j != i:                num = polymul(num, [-xj % P, 1])                den = den * (xi - xj) % P        s = yi * pow(den, -1, P) % P        for k in range(len(num)):            coeffs[k] = (coeffs[k] + s * num[k]) % P    return coeffs​​def evaluate(c, x):    return sum(ck * pow(x, k, P) for k, ck in enumerate(c)) % P​​def decode(pts):    assert len({x for x, _ in pts}) == len(pts)    for subset in itertools.combinations(pts, 8):        c = interpolate(list(subset))        good = [p for p in pts if evaluate(c, p[0]) == p[1]]        if len(good) >= 12 and all(v < 256 for v in c):            bad = [p for p in pts if p not in good]            return bytes(c), bad    raise ValueError("no codeword found")​​worlds = {}for w in ("overworld", "nether", "the_end"):    key, bad = decode(load(w))    worlds[w] = key    print(f"{w:10} coeffs={key.hex()} forged={bad}")worlds["echo"] = bytes.fromhex(open("the_echo/core.hex").read())print(f"{'echo':10} coeffs={worlds['echo'].hex()}")​ikm = bytes(b for i in range(8) for b in (worlds["overworld"][i], worlds["nether"][i], worlds["the_end"][i], worlds["echo"][i]))print("ikm =", ikm.hex())​v = json.load(open("the_echo/vault.json"))key = HKDF(hashes.SHA256(), 32, bytes.fromhex(v["salt_hex"]), v["info_ascii"].encode()).derive(ikm)pt = AESGCM(key).decrypt(bytes.fromhex(v["nonce_hex"]),                         bytes.fromhex(v["ciphertext_hex"]) + bytes.fromhex(v["tag_hex"]),                         v["aad_ascii"].encode())print(pt.decode())

06

Technical explanation

Evaluating a degree-7 polynomial at 16 distinct points is a Reed–Solomon code with n = 16 and k = 8. Its minimum distance is 9, so up to four corrupted points can be corrected uniquely. Brute-forcing all 12,870 subsets of 8 points per world is fast, and the uniqueness argument (two degree-7 polynomials agreeing on 8 points are identical) guarantees the first good candidate is the right one.

Key lessons

  • "Polynomial of degree k−1 evaluated at n points, some of them corrupted" is Reed–Solomon. Up to (n − k)/2 errors can be corrected uniquely.

  • For small parameters, brute-forcing subsets and interpolating is faster to write than Berlekamp–Welch and just as correct.

  • An AEAD tag is a free correctness check for the whole pipeline: if GCM decrypts, the key material was right.

07

Flag

Flag

TVX{th3_3ch0_b1nds_th3_f0ur_w0rlds}

Flag recovered locally · platform unverified

08

Verification status

Status: Flag recovered locally; platform acceptance not documented.

AES-256-GCM authenticates before it returns plaintext, so the successful decryption proves that every recovered coefficient, the interleaving and the HKDF parameters were correct. The full script output is reproduced below. Platform acceptance is not documented.

Source evidence in the archive: WRITEUP.md, solve.py, images/00_challenge.png.

09

Conclusion

A clean coding-theory challenge. The authenticated encryption at the end acts as a built-in checksum for the whole pipeline.

Prepared by Adam Omar Saleh from the archived solve notes in the_fourth_portal/. Commands, code, output and screenshots are reproduced from the source; no results were added. Difficulty is an estimate.

PDF edition

Writeup PDF

Formatted edition of this walkthrough, built from my source notes · 6 pages.