defsuan_p01y(nt, db): returnsum(x^i for i inset(sample(range(db+1), nt)))
whileTrue: t = [suan_p01y(d, r//3) for _ inrange(2)] if gcd(t[0], t[1]) != 1: continue h = [(ti * X^ZZ.random_element(r)) for ti in t] if h[0].is_unit(): break
use ark_bls12_381::{Fr, G1Projective}; use ark_ec::{AffineRepr, CurveGroup, PrimeGroup}; use ark_ec::pairing::Pairing; use ark_std::UniformRand; use rand::rngs::OsRng;
use ark_bls12_381::{Bls12_381, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; use ark_ec::{hashing::{ curve_maps::wb::WBMap, map_to_curve_hasher::MapToCurveBasedHasher, HashToCurve, }, pairing::Pairing, CurveGroup, PrimeGroup}; use ark_ff::{field_hashers::DefaultFieldHasher, Field, PrimeField, UniformRand, Zero}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use rand::rngs::OsRng; use sha2::{Digest, Sha256}; use std::io;
for rnd inrange(1, ROUNDS + 1): suan_fn = suanhash_fn()
print(f"[Round {rnd}]", flush=True)
seen = {} # hash -> msg collided = False
for q inrange(1, QUERIES_PER_ROUND + 1): msg = bytes.fromhex(input(f"💬 MSG {q} (hex): ").strip()) h = suan_fn(msg) print(f"H = {h}", flush=True) if h in seen and seen[h] != msg: collided = True else: seen[h] = msg
ifnot collided: print("❌ No hash collision in this round. Game over.") exit(-1) else: print("✅ Hash collision found! Next round.\n", flush=True)
print(f"🎉 Nice! Here is your flag: {os.environ.get('FLAG', 'RCTF{fake_flag}')}")
defrecv_hash(p) -> str: """Read a line like 'H = <hex>' and return the hex digest.""" whileTrue: line = p.recvline().decode(errors="ignore").strip() if line.startswith("H = "): return line.split(" = ", 1)[1]
defmain(): # Use the current interpreter to avoid path issues on Windows/WSL. p = process( [sys.executable, "task.py"], cwd=".", env=dict(os.environ, PWNLIB_NOTERM="1"), stderr=STDOUT, # surface import/runtime errors )
# Skip banner until the first prompt of round 1. ifnot p.can_recv(timeout=5): buf = p.recvall(timeout=1) print(f"[!] No banner/prompt, got: {buf!r}") return try: p.recvuntil(b"MSG 1", timeout=5) except Exception: buf = p.recv(timeout=1) print(f"[!] Did not find 'MSG 1' prompt, got: {buf!r}") return
# Read collision status status = p.recvline().decode(errors="ignore") if"Hash collision found"notin status: print(f"[!] Unexpected response at round {rnd}: {status.strip()}") return
if rnd < ROUNDS: # Skip to the next round's first prompt p.recvuntil(b"MSG 1") else: # Final round: expect the flag line next flag_line = p.recvline().decode(errors="ignore").strip() print(flag_line) rest = p.recvall(timeout=1).decode(errors="ignore").strip() if rest: print(rest) return