Modular Binomial Equation Attack
- •
What it is
- •
A technique for recovering the two prime factors of when you're given two ciphertexts that are each a linear combination of and raised to a public exponent: , .
- •
- •
When to apply
- •
is given, and both ciphertexts are visibly "binomial" — small known integer coefficients multiplying and before exponentiation. That coefficient structure is the tell.
- •
- •
- •
- •
Python
- •
expr = (pow(a2, -e1 * e2, N) * pow(c2, e1, N) - pow(a1, -e1 * e2, N) * pow(c1, e2, N)) % N q = math.gcd(expr, N) p = N // q
- •
- •
SageMath
- •
expr = mod(power_mod(a2, -e1*e2, N) * power_mod(c2, e1, N) - power_mod(a1, -e1*e2, N) * power_mod(c1, e2, N), N) q = gcd(Integer(expr), N)
- •
- •
- •
Cards
- •
What structural clue in a challenge suggests the modular binomial attack?
- •
N = p·q given, alongside two ciphertexts each of the form (small_int·p + small_int·q)^e mod N.
- •
- •
Why does the key expression end up divisible by q?
- •
Because modulo q the q-term of the binomial vanishes, making both scaled terms equal to , so their difference is 0 mod q.
- •
- •