Find a collision for my hash algorithm! It is basically military-graded: The output is 256-bit long, and discrete log is hard! I even made it harder such that you don't even have the public parameters!

Challenge contributed by Mystiz

Connect at archive.cryptohack.org 56434

Challenge files:

  • chall.py#!/usr/bin/python3

Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

from Crypto.Util.number import getPrime as get_prime import math import random import os import hashlib

Suppose gcd(p, q) = 1. Find x such that

1. 0 <= x < p * q, and

2. x = a (mod p), and

3. x = b (mod q).

def crt(a, b, p, q): return (a*pow(q, -1, p)q + bpow(p, -1, q)p) % (pq)

def L(x, n): return (x-1) // n

class Paillier: def init(self): p = get_prime(1024) q = get_prime(1024)

    n = p * q
    λ = (p-1) * (q-1) // math.gcd(p-1, q-1) # lcm(p-1, q-1)
    g = random.randint(0, n-1)
    µ = pow(L(pow(g, λ, n**2), n), -1, n)

    self.n = n
    self.λ = λ
    self.g = g
    self.µ = µ

    self.p = p
    self.q = q

# https://www.rfc-editor.org/rfc/rfc3447#section-7.2.1
def pad(self, m):
    padding_size = 2048//8 - 3 - len(m)
    
    if padding_size < 8:
        raise Exception('message too long')

    random_padding = b'\0' * padding_size
    while b'\0' in random_padding:
        random_padding = os.urandom(padding_size)

    return b'\x00\x02' + random_padding + b'\x00' + m

def unpad(self, m):
    if m[:2] != b'\x00\x02':
        raise Exception('decryption error')

    random_padding, m = m[2:].split(b'\x00', 1)

    if len(random_padding) < 8:
        raise Exception('decryption error')

    return m

def public_key(self):
    return (self.n, self.g)

def secret_key(self):
    return (self.λ, self.µ)

def encrypt(self, m):
    g = self.g
    n = self.n

    m = self.pad(m)
    m = int.from_bytes(m, 'big')

    r = random.randint(0, n-1)
    c = pow(g, m, n**2) * pow(r, n, n**2) % n**2

    return c

def decrypt(self, c):
    λ = self.λ
    µ = self.µ
    n = self.n

    m = L(pow(c, λ, n**2), n) * µ % n
    m = m.to_bytes(2048//8, 'big')

    return self.unpad(m)

def fast_decrypt(self, c):
    λ = self.λ
    µ = self.µ
    n = self.n
    p = self.p
    q = self.q

    rp = pow(c, λ, p**2)
    rq = pow(c, λ, q**2)
    r = crt(rp, rq, p**2, q**2)
    m = L(r, n) * µ % n
    m = m.to_bytes(2048//8, 'big')

    return self.unpad(m)

def challenge(p): secret = os.urandom(2) secret = hashlib.sha512(secret).hexdigest().encode()

c0 = p.encrypt(secret)
print(f'{c0 = }')

# # The secret has 16 bits of entropy.
# # Hence 16 oracle calls should be sufficient, isn't it?
# for _ in range(16):
#     c = int(input())
#     try:
#         p.decrypt(c)
#         print('😀')
#     except:
#         print('😡')

# I decided to make it non-interactive to make this harder.
# Good news: I'll give you 25% more oracle calls to compensate, anyways.
cs = [int(input()) for _ in range(20)]
for c in cs:
    try:
        p.fast_decrypt(c)
        print('😀')
    except:
        print('😡')

guess = input().encode()

if guess != secret: raise Exception('incorrect guess!')

def main(): flag = os.environ.get('FLAG', 'CTF{REDACTED}')

p = Paillier()
n, g = p.public_key()
print(f'{n = }')
print(f'{g = }')

try:
    # Once is happenstance. Twice is coincidence...
    # Sixteen times is a recovery of the pseudorandom number generator.
    for _ in range(16):
        challenge(p)
        print('💡')
    print(f'🏁 {flag}')
except:
    print('👋')

if name == 'main': main()you are ctf experYou are an expert cybersecurity assistant specialized in Capture The Flag (CTF) style problem solving. Your role is to help solve technical challenges across domains including Web Exploitation, Cryptography, Forensics, Reverse Engineering, OSINT, Binary Exploitation, and Miscellaneous categories.

Operate with a problem-solving mindset:

  • Break down each challenge logically before attempting solutions.
  • Identify patterns, anomalies, and likely attack vectors.
  • Prioritize efficiency and avoid unnecessary brute force unless justified.

Response style:

  • Be concise, structured, and action-oriented.
  • Always suggest next steps, not just explanations.
  • When applicable, provide commands, scripts, or tools to use.
  • If multiple approaches exist, briefly list them in order of likelihood.

Technical behavior:

  • Assume access to common tools (e.g., CyberChef, Wireshark, Burp Suite, Ghidra, binwalk, strings, steghide, etc.).
  • Suggest practical commands (bash, Python, etc.) when relevant.
  • For encoded or encrypted data, attempt identification before decoding.
  • For web challenges, think in terms of vulnerabilities (SQLi, XSS, SSRF, LFI/RFI, auth bypass, etc.).
  • For crypto, analyze type (substitution, RSA, XOR, hashing flaws, etc.) before solving.
  • For forensics, guide step-by-step artifact analysis.
  • For reverse engineering, suggest static and dynamic approaches.

Reasoning:

  • Show clear step-by-step thinking when solving problems.
  • If unsure, propose hypotheses and how to test them.
  • Avoid guessing flags—derive them logically.

Interaction:

  • Ask for missing details if needed (files, outputs, links).
  • Adapt based on new information provided.
  • Do not give generic theory unless explicitly asked—focus on solving.

Goal: Help efficiently analyze and solve technical challenges with a strong focus on practical execution, clear reasoning, and minimal wasted effort. Time and efficiency are critical. Avoid long explanations. Focus on the fastest path to a solution. If a path seems unproductive, suggest switching strategies quickly. do not randomly guess since there is negative marking involved; have a proper logical (with proof) solution for every flag you calculate _**

Dr.Binary
You stopped this response.
output_08c8185f76be72ad28168594b4459b2a.txt
babai_signatures_b22ce3234dffc87c8c7aea5bfbe5f3a3.py
              Babai's Parallelepiped175 pts · 24 Solves

Before the GPV framework (and FALCON's Fast Fourier Sampling), early lattice signature schemes like GGH and NTRUSign signed messages by rounding a target vector to the nearest lattice point using Babai's Round-Off algorithm:

z

⌊ t B − 1 ⌉ , s

t − z B z=⌊tB −1 ⌉,s=t−zB

Because s

ϵ B s=ϵB with ϵ ∈ [ − 1 / 2 , 1 / 2 ) d ϵ∈[−1/2,1/2) d , every signature leaks a point uniformly sampled from the secret fundamental parallelepiped P ( B ) P(B). In 2006, Nguyen and Regev showed that collecting enough signatures allows an attacker to completely recover the secret basis B B without even knowing the public key.

Recover the secret basis B B from the 5000 signatures in output.txt and use it to decrypt the flag.

Compute the empirical covariance matrix Σ ≈ 1 12 B T B Σ≈ 12 1 ​ B T B and whiten the signatures: Y

S Σ − 1 / 2 Y=SΣ −1/2 .

Challenge files:

  • babai_signatures.py
  • output.txt you are ctf experYou are an expert cybersecurity assistant specialized in Capture The Flag (CTF) style problem solving. Your role is to help solve technical challenges across domains including Web Exploitation, Cryptography, Forensics, Reverse Engineering, OSINT, Binary Exploitation, and Miscellaneous categories.

Operate with a problem-solving mindset:

  • Break down each challenge logically before attempting solutions.
  • Identify patterns, anomalies, and likely attack vectors.
  • Prioritize efficiency and avoid unnecessary brute force unless justified.

Response style:

  • Be concise, structured, and action-oriented.
  • Always suggest next steps, not just explanations.
  • When applicable, provide commands, scripts, or tools to use.
  • If multiple approaches exist, briefly list them in order of likelihood.

Technical behavior:

  • Assume access to common tools (e.g., CyberChef, Wireshark, Burp Suite, Ghidra, binwalk, strings, steghide, etc.).
  • Suggest practical commands (bash, Python, etc.) when relevant.
  • For encoded or encrypted data, attempt identification before decoding.
  • For web challenges, think in terms of vulnerabilities (SQLi, XSS, SSRF, LFI/RFI, auth bypass, etc.).
  • For crypto, analyze type (substitution, RSA, XOR, hashing flaws, etc.) before solving.
  • For forensics, guide step-by-step artifact analysis.
  • For reverse engineering, suggest static and dynamic approaches.

Reasoning:

  • Show clear step-by-step thinking when solving problems.
  • If unsure, propose hypotheses and how to test them.
  • Avoid guessing flags—derive them logically.

Interaction:

  • Ask for missing details if needed (files, outputs, links).
  • Adapt based on new information provided.
  • Do not give generic theory unless explicitly asked—focus on solving.

Goal: Help efficiently analyze and solve technical challenges with a strong focus on practical execution, clear reasoning, and minimal wasted effort. Time and efficiency are critical. Avoid long explanations. Focus on the fastest path to a solution. If a path seems unproductive, suggest switching strategies quickly. do not randomly guess since there is negative marking involved; have a proper logical (with proof) solution for every flag you calculate ](streamdown:incomplete-link)

Dr.Binary
read_file
run_sandbox

Looking at this challenge: we have 5000 signatures s = t - zB which are exactly uniform samples from the fundamental parallelepiped P(B) of the secret basis (B = 6I + E, E ∈ {-1,0,1}^16). This is the classic Nguyen–Regev "learning a parallelepiped" attack — recover B via ICA (4th-cumulant joint diagonalization), verify exactly (all sB⁻¹ must lie in [-1/2,1/2)¹⁶), then derive the SHA-256 key from the canonicalized basis and XOR-decrypt.

Let me set up a plan and verify my solver on simulated data first.](streamdown:incomplete-link)

todo_write

Looking at this challenge: signatures s = ε·B with ε ∈ [-1/2,1/2)^16 uniform — classic Nguyen–Regev parallelepiped recovery. Plan:

  1. Whiten with empirical covariance (Σ ≈ BᵀB/12) → data becomes a rotated cube.
  2. Find the rotation via 4th-moment ICA (Jacobi sweeps minimizing Σ E[(Z·o)⁴]² — for a uniform cube the axes have the minimal 4th moment 1/80, provably the global min over rotations).
  3. Reconstruct B = √12·Oᵀ·Σ^{1/2}, round to integers, verify S·B⁻¹ ∈ [-1/2,1/2)^16 for all 5000 signatures (exact certificate), canonicalize, derive the SHA-256 keystream, XOR-decrypt.
write_file
run_sandbox

J found (0.00337) is well above the theoretical cube minimum (0.0025) — ICA is stuck in a local minimum. Let me debug the pipeline on synthetic data with a known basis, then add restarts:

write_file
run_sandbox

The pipeline fails even on synthetic data with known B — so it's an optimization/convergence issue, not a formula issue. Let me diagnose: compute J at the true rotation vs what Jacobi found, and check for sklearn:

write_file
run_sandbox

Critical findings: the reconstruction formula B = √12·Oᵀ·Σ^{1/2} is exact (round err 1e-14), and J at the true rotation is 0.00255 < J(identity) = 0.00345 — yet Jacobi "from identity" reported J=0.00421, which is impossible for non-increasing coordinate descent. There's a bug. Let me instrument:

write_file
run_sandbox

No per-pair increase was detected, yet J grows — the pair-step prediction is inconsistent with the true objective. Let me isolate with a direct before/after comparison on a single pair:

write_file
run_sandbox

Found the bug! In the second direction w = -s·u + c·v, the term 4a³b·E[u³v] = -4·s³·c·M31 — but I coded -4·M31·c³·s (powers of c and s swapped). Same for the 4ab³ term. The prediction for T4₀ matches exactly but T4₁ doesn't (0.015943 predicted vs 0.016171 actual) — the pairwise objective was wrong, so "descent" wasn't descending the true J. Fixing:

edit_file
run_sandbox

Now Jacobi descends properly (0.00345 → 0.00302) but stalls at a local minimum (true rotation J=0.00255). The 4th-moment landscape is too rough for coordinate descent alone. I'll add two stronger objectives and a chaining strategy: (a) exact 6th-moment Jacobi (much stronger signal: axis 1/448 vs generic ≈15/1728), and (b) RADICAL-style spacing-entropy Jacobi (uniform marginals have entropy ≈ 0 — ideal for uniform sources), then chain 4th → 6th → entropy polishing:

write_file
run_sandbox

Both moment objectives now hit their theoretical minima, yet reconstruction is off by ~0.19 — the optimizer is overfitting sampling noise (found J4 below the true rotation's 0.00255). But Bnum is now close to the integer lattice. Strategy: take Bint = rint(Bnum) as a starting guess and do a structured discrete hill-climb on F(B) = ‖BᵀB − 12Σ‖² (the true basis is the unique structured matrix fitting the Gram matrix), then verify with the exact box certificate. Let me test on synthetic first:

write_file
run_sandbox

Breakthrough insight: the box check PASSES for the rounded matrix (max|ε| = 0.4999975 — exactly the true-solution signature)! The failure is my structure check: ICA recovers B0 = Pᵀ·B_true — a row-permuted basis — so entries B0 − 6I aren't in {-1,0,1} even though each row is intact (its 6 sits at a permuted column). Row permutations/signs are exactly what canonicalize_basis handles. Fixing the validation to check rows individually:

edit_file
run_sandbox

Full certificate passes on synthetic now (the |B_true| elementwise compare fails only because rows are permuted — let me confirm canonical forms match, then run on the real data):

write_file
run_sandbox

Flag recovered: crypto{b4b4i_r0und1ng_l34ks_th3_p4r4ll3l3p1p3d}

Let me run the definitive end-to-end verification — re-encrypt the decrypted flag with the recovered basis and confirm it matches the original ciphertext, plus check all 5000 signatures map into the box:

run_sandbox

✅ Solved — flag: crypto{b4b4i_r0und1ng_l34ks_th3_p4r4ll3l3p1p3d}

Solution path

Attack (Nguyen–Regev parallelepiped recovery, as hinted):

  1. Whiten: Σ = SᵀS/N ≈ BᵀB/12, Z = (S−S̄)·Σ^{-1/2}/√12. Since B·Σ^{-1/2}/√12 is orthogonal, the signatures become a uniformly filled rotated hypercube — cov(Z)=I/12, but orientation unknown.
  2. Find the rotation by ICA: for the cube, every axis direction has 4th moment exactly 1/80 (min possible, since T4(o) = 1/48 − Σoᵢ⁴/120 is minimized only at signed axes — provable global min). I ran pairwise Jacobi sweeps with exact 1-D minimization of Σⱼ E[(Z·oⱼ)ᵖ]² for p=4 and p=6 (exact moment expansions of E[(c·u+s·v)ᵖ]), plus RADICAL-style spacing-entropy sweeps (uniform marginals ⇒ entropy ≈ 0), chained 4th→6th→entropy→4th→6th.
  3. Reconstruct: Bnum = √12·Oᵀ·Σ^{1/2}, round to integers. ICA returns B up to row permutation/sign — harmless, canonicalize_basis eliminates both.
  4. Decrypt: canonicalize → sha256(json.dumps(canon)) → SHA-256 counter keystream → XOR.

Key debugging moments

  • A sign/power bug in the second direction of the pairwise 4th-moment expansion (−4·M31·c³s instead of −4·M31·s³c) made "descent" climb — caught by checking predicted vs brute-forced moments.
  • Coordinate descent alone stalled at a local min (J=0.00302 vs true 0.00255); chaining stronger statistics fixed it.
  • My structure check wrongly demanded B−6I ∈ {−1,0,1} elementwise, rejecting the correct row-permuted basis — the box certificate (max|ε|=0.4999959 < 0.5, boundary touched in all 16 coordinates) revealed it was already right.

Proof of correctness (not a guess)

  • All 5000 signatures satisfy s·B⁻¹ ∈ [−1/2,1/2)¹⁶ with |det| = 2,589,459,339,419 ≠ 0, and every filter coordinate hits the boundary (expected extreme-value statistics of 5000 uniforms) — the exact certificate babai_sign guarantees only for the true basis.
  • End-to-end: re-encrypting the decrypted flag with the recovered canonical basis reproduces enc_flag byte-for-byte, and on synthetic data with a known basis the identical pipeline reproduced the ground-truth canonical form and SHA-256 key exactly.

Scripts: pipeline.py (ICA engine), solve_real.py (full solve), test_synthetic.py/refine.py (validation).

13440_2c0bc8dcf1e230b5568e23e7b5f6a9ba.py

During FALCON key generation, you start with two short secret polynomials f , g ∈ Z [ x ] / ( x n + 1 ) f,g∈Z[x]/(x n +1) and must complete them into a full NTRU lattice basis by finding short F , G ∈ Z [ x ] / ( x n + 1 ) F,G∈Z[x]/(x n +1) satisfying:

f G − g F

q fG−gF=q

Solving this directly in degree n n is hard, so FALCON exploits the tower of cyclotomic fields Q [ x ] / ( x n + 1 ) ⊃ Q [ x ] / ( x n / 2 + 1 ) ⊃ ⋯ ⊃ Q Q[x]/(x n +1)⊃Q[x]/(x n/2 +1)⊃⋯⊃Q to recursively halve the degree down to integers, then lift and reduce the solution back up.

Given the server's f f and g g, find F , G F,G satisfying the NTRU equation with ∥ ( F , G ) ∥ 2 ≤ 600 ∥(F,G)∥ 2 ​ ≤600 to get the flag.

Split a polynomial into even and odd parts a ( x )

a e ( x 2 ) + x a o ( x 2 ) a(x)=a e ​ (x 2 )+xa o ​ (x 2 ). Its field norm is N ( a ) ( y )

a e ( y ) 2 − y a o ( y ) 2 ∈ Z [ y ] / ( y n / 2 + 1 ) N(a)(y)=a e ​ (y) 2 −ya o ​ (y) 2 ∈Z[y]/(y n/2 +1).

Connect at socket.cryptohack.org 13440

Challenge files:

  • 13440.pyyou are ctf experYou are an expert cybersecurity assistant specialized in Capture The Flag (CTF) style problem solving. Your role is to help solve technical challenges across domains including Web Exploitation, Cryptography, Forensics, Reverse Engineering, OSINT, Binary Exploitation, and Miscellaneous categories.

Operate with a problem-solving mindset:

  • Break down each challenge logically before attempting solutions.
  • Identify patterns, anomalies, and likely attack vectors.
  • Prioritize efficiency and avoid unnecessary brute force unless justified.

Response style:

  • Be concise, structured, and action-oriented.
  • Always suggest next steps, not just explanations.
  • When applicable, provide commands, scripts, or tools to use.
  • If multiple approaches exist, briefly list them in order of likelihood.

Technical behavior:

  • Assume access to common tools (e.g., CyberChef, Wireshark, Burp Suite, Ghidra, binwalk, strings, steghide, etc.).
  • Suggest practical commands (bash, Python, etc.) when relevant.
  • For encoded or encrypted data, attempt identification before decoding.
  • For web challenges, think in terms of vulnerabilities (SQLi, XSS, SSRF, LFI/RFI, auth bypass, etc.).
  • For crypto, analyze type (substitution, RSA, XOR, hashing flaws, etc.) before solving.
  • For forensics, guide step-by-step artifact analysis.
  • For reverse engineering, suggest static and dynamic approaches.

Reasoning:

  • Show clear step-by-step thinking when solving problems.
  • If unsure, propose hypotheses and how to test them.
  • Avoid guessing flags—derive them logically.

Interaction:

  • Ask for missing details if needed (files, outputs, links).
  • Adapt based on new information provided.
  • Do not give generic theory unless explicitly asked—focus on solving.

Goal: Help efficiently analyze and solve technical challenges with a strong focus on practical execution, clear reasoning, and minimal wasted effort. Time and efficiency are critical. Avoid long explanations. Focus on the fastest path to a solution. If a path seems unproductive, suggest switching strategies quickly. do not randomly guess since there is negative marking involved; have a proper logical (with proof) solution for every flag you calculate

Challenge contributed by maksushka

Dr.Binary
read_file

Falcon key generation: solve f·G − g·F = q in Z[x]/(x³²+1) with ‖(F,G)‖ ≤ 600. Note generate_fg uses seed 2026, so f,g are deterministic — I can solve fully offline, then connect and submit.

Plan:

  1. Reproduce f,g locally (seed 2026).
  2. Tower solve (Falcon style): recurse f,g → N(f),N(g) down to scalars, solve f₀G − g₀F = q by extended gcd, lift back up via N(f)(x²) = f·f(−x) → exact particular solution (F₀,G₀).
  3. Size-reduce: kernel lattice L = {(F,G): fG−gF=0} ⊇ {(f·xⁱ, g·xⁱ)}, LLL + Babai nearest-plane to get a short representative.
  4. Verify locally, then submit.
run_sandbox

No fpylll — I'll write pure-Python LLL (dim 32, tiny entries). Port is reachable. First grab f,g from the server and confirm they match seed-2026 generation:

write_file
run_sandbox

Server deterministic (seed 2026) — f,g match. Now the solver: tower descent + lift, then LLL + Babai on the kernel lattice:

write_file
run_sandbox

Timeout — my Fraction-based incremental GSO explodes. Rewriting LLL with float GSO + exact integer basis updates (safe here: LLL only steers the search; the final (F,G) is verified exactly in Z), and exact-Fraction Babai:

write_file
run_sandbox

Two findings: (1) tower norm 4.6e+101 is expected (field norms square each level, so the final scalars ~1e79 — exact ints, no problem); (2) real bug: in Babai I subtracted r·b*_i instead of r·B[i] — that breaks integrality of the lattice point. Fixing:

edit_file
run_sandbox

Solved: ‖(F,G)‖ = 286.33 ≤ 600, NTRU equation holds exactly. Now connect and submit — recomputing from whatever f,g the server actually sends (in case), then posting the solution:

write_file
run_sandbox

✅ Flag: crypto{n7ru_t0w3r_0f_f13lds_m4st3r3d} (server accepted the solution; the traceback was only my post-processing regex, the raw response shows the flag).

Solution summary

Problem: solve f·G − g·F = q exactly in Z[x]/(x³²+1) with ‖(F,G)‖₂ ≤ 600, q=12289.

Approach (Falcon tower + lattice reduction):

  1. Deterministic f,g — generate_fg(N, seed=2026) let me reproduce the server's polynomials offline and verify against the banner.

  2. Tower descent — recurse f,g → N(f),N(g) (field norm ae² − y·ao²) down to scalars. Verified the key lift identity in-code: N(f)(x²) = f·f(−x) mod (xⁿ+1). Base case solves f₀G − g₀F = q by extended gcd (gcd=1 guaranteed by the challenge's has_ntru_solution).

  3. Lift — q = N(f)G_h − N(g)F_h ⇒ f·[f(−x)G_h(x²)] − g·[g(−x)F_h(x²)] = q, giving an exact particular solution with norm ~4.6·10¹⁰¹ (field norms square each level — expected, harmless with Python bigints; every level's equation asserted exactly).

  4. Size reduction — the solution set is (F₀,G₀) + L with kernel lattice L ⊇ {(f·xⁱ, g·xⁱ)} (32 vectors in ℤ⁶⁴, entries ≤15). Built that basis, ran exact-integer LLL with float GSO (incremental Gram–Schmidt updates; integer basis updates keep everything exact), then Babai nearest-plane with exact Fraction GSO targeting −(F₀,G₀) plus 3 polish rounds.

Two bugs caught en route (both by assertions, not luck): a wrong GSO-swap sign family, and subtracting r·b*_i instead of r·B[i] in Babai (broke integrality of the lattice point).

Result: ‖(F,G)‖ = 286.33, poly_mul(f,G) − poly_mul(g,F) == [12289,0,…,0] verified with the challenge's own functions before submission.

Files: chal_defs.py, solve_ntru.py, submit.py, solution.json.