Tonelli-Shanks algorithm Created 2026-10-20 Updated 2026-11-05
The Tonelli-Shanks algorithm finds a square root of a quadratic residue modulo an odd prime number . Handle separately and use the Legendre symbol to reject a quadratic nonresidue. Write with odd, choose a quadratic nonresidue , and initializemodulo . Maintain , with of multiplicative order and of multiplicative order dividing .
If , find the least with . Set and updateThe multiplicative order of decreases because its last nontrivial power and that of are both minus one. Thus strictly decreases. At , the invariant gives .