TVX CTF 2026Cryptography
Creeper's Shared Prime
Two RSA public keys were built from “parts stolen from the same crafting table”. A message encrypted for Vault A must be recovered.
- Competition
TVX CTF 2026
- Category
- CryptographyEasy · estimated
- Source status
- Flag recovered locally · platform unverified
- Document
- PDF edition3 min read
Brief
The challenge
- Competition
- TVX CTF 2026
- Category
- Cryptography (platform category: Crypto)
- Difficulty
- Easy — estimated, not an official rating
- Points
- 100
- Challenge author
- Ayham Al-Qaisi
- Verification
- Flag recovered locally; platform acceptance not documented
Difficulty: Easy (estimated). TVX CTF 2026 did not publish difficulty ratings; the challenge cards show only points and solve counts. A textbook RSA weakness: two moduli share a prime, and one
gcdfactors them. The rest is standard RSA decryption in a few lines of Python.
01
Overview
A Creeper built two RSA vaults with parts stolen from the same crafting table. The message was encrypted for Vault A. Recover it.
Two RSA public keys were built from “parts stolen from the same crafting table”. A message encrypted for Vault A must be recovered.
Solution path in brief
The two RSA moduli share a prime factor. Taking gcd(n_A, n_B) factors Vault A's modulus immediately, which gives the private key and the plaintext.
gcd(n_A, n_B) → p → q = n_A / p → d = e⁻¹ mod φ(n_A) → m = c^d mod n_A02
Initial investigation
The first step was to compare the two public keys and the ciphertext parameters.
Recon
public_keys.txt contains two RSA public keys with the same exponent e = 65537:
n_A = 1942668892225729070919461906823520455305416829490420089422957436437580309796491507761n_B = 1942668892225729070919461906823519371241578281403951004079222153957205455266330293941ciphertext.txt contains one ciphertext c encrypted for Vault A.
The hints all point the same way: "parts stolen from the same crafting table", "the same careless Creeper", and the title "Shared Prime".
03
Tools used
Python 3 (
math.gcd, modular inverse viapow)
04
Step-by-step process
Step 1: Factoring with the gcd
If two moduli are n_A = p·q_A and n_B = p·q_B, their greatest common divisor is p. Euclid's algorithm computes it instantly, regardless of key size:
p = 1393796574908163946345982392040522705234977q_A = 1393796574908163946345982392040523594123793p · q_A == n_A checks out.
Step 2: Decrypting
With both factors known:
φ(n_A) = (p − 1)(q_A − 1)d = 65537⁻¹ mod φ(n_A)m = c^d mod n_AConverting m to bytes gives the flag.
05
Commands and code
Solve script
solve.py:
import refrom math import gcdkeys = open("public_keys.txt").read()n_a, n_b = (int(x) for x in re.findall(r"n = (\d+)", keys))e = 65537c = int(re.search(r"c = (\d+)", open("ciphertext.txt").read()).group(1))p = gcd(n_a, n_b)q = n_a // passert p * q == n_a and 1 < p < n_ad = pow(e, -1, (p - 1) * (q - 1))m = pow(c, d, n_a)print(m.to_bytes((m.bit_length() + 7) // 8, "big").decode())Full source: solve.py
import refrom math import gcdkeys = open("public_keys.txt").read()n_a, n_b = (int(x) for x in re.findall(r"n = (\d+)", keys))e = 65537c = int(re.search(r"c = (\d+)", open("ciphertext.txt").read()).group(1))p = gcd(n_a, n_b)q = n_a // passert p * q == n_a and 1 < p < n_ad = pow(e, -1, (p - 1) * (q - 1))m = pow(c, d, n_a)print(m.to_bytes((m.bit_length() + 7) // 8, "big").decode())06
Technical explanation
RSA security depends on the primes being secret and unique to each key. If two moduli share a prime p, then gcd(n_A, n_B) = p, which the Euclidean algorithm finds instantly regardless of key size. With p known, q = n_A / p, φ(n_A) = (p-1)(q-1), and the private exponent is the inverse of e modulo φ(n_A).
Key lessons
Whenever you get more than one RSA modulus, try
gcdon every pair first. It costs nothing.Reusing a prime across keys, usually because of a weak RNG, breaks every key that shares it.
07
Flag
Flag
TVXCTF{the_creeper_reused_a_prime}
Flag recovered locally · platform unverified
08
Verification status
Status: Flag recovered locally; platform acceptance not documented.
The decryption produces readable plaintext in the flag format, and the script asserts that the recovered factors multiply back to the modulus. Platform acceptance is not documented.
Source evidence in the archive: WRITEUP.md, solve.py, public_keys.txt, ciphertext.txt.
09
Conclusion
A classic shared-factor attack. It shows why weak randomness during key generation breaks RSA even when every key is large.
Prepared by Adam Omar Saleh from the archived solve notes in creepers_shared_prime/. Commands, code, output and screenshots are reproduced from the source; no results were added. Difficulty is an estimate.