Recovering an Unknown Modulus via GCD (Successive Powers)
- •
What it is
- •
A technique for recovering an unknown prime modulus from a sequence of consecutive powers of an unknown base , given only the sequence values (neither nor stated). Consecutive terms satisfy the ratio identity ; cross-multiplying gives — an integer (computed over the plain integers, no modular arithmetic needed) that divides exactly. Computing this difference from two or more overlapping triples gives several integers that are all multiples of ; their GCD is generally itself (or a small multiple of it, resolved by stripping small factors and checking primality/bit-length).
- •
- •
When to apply
- •
You're given a sequence of integers described as "successive powers of x modulo a prime p", with neither p nor x stated.
- •
- •
Math
- •
for every valid , since all three terms share the common ratio . Once is known, for any .
- •
- •
Worked example
- •
Sequence
[588,665,216,113,642,4,836,114,851,492,819,237]. Taking and : , . , and 919 is the three-digit prime the challenge asked for. Then — and this pair reproduces the entire 12-term sequence exactly as , confirmed by direct check.
- •
- •
Python
- •
from math import gcd D1 = seq[i+1]**2 - seq[i]*seq[i+2] D2 = seq[j+1]**2 - seq[j]*seq[j+2] p_candidate = gcd(D1, D2) # p_candidate may be p times a small integer factor -- strip small factors # and check primality / expected bit-length to isolate p itself x = (seq[i+1] * pow(seq[i], -1, p)) % p
- •
- •
- •
Cards
- •
What identity lets you compute an integer multiple of the unknown modulus from three consecutive sequence terms?
- •
, computed as a plain integer (not reduced) that p divides exactly.
- •
- •
Why do you need at least two different triples from the sequence, not just one?
- •
A single difference could be a large multiple of p; taking the GCD of two (or more) such differences strips out the extraneous factors and isolates p itself.
- •
- •