Shanks Algorithm
When the prime modulus satisfies , computing the square root of a quadratic residue becomes remarkably simple when is odd. This is because the field size then satisfies , enabling a shortcut formula for extracting square roots. The method is based on Algorithm 2 from ePrint 2012/685.
Goal
Find such that:
if is a quadratic residue.
Original Algorithm
The algorithm consists of the following steps:
Compute
Compute
If , then is a quadratic nonresidue
Otherwise, return
This version performs:
1 exponentiation,
1 squaring,
2 multiplications.
Modified Algorithm
A simplified version is often used in practice:
Compute
If , return
Otherwise, is a quadratic nonresidue
This version only requires:
1 exponentiation,
1 squaring
and defers the residuosity check to a final comparison.
Why It Works (when )
To understand why this shortcut is valid, consider the case where and . Suppose is a square root of , i.e.,
Then,
We know:
But since , taking the 4th root of both sides gives:
Therefore, is indeed a valid square root of — if is a quadratic residue.
Why It Requires to Be Odd
In the general case over , we require the field size to satisfy for the exponent to be an integer and the formula to hold. This congruence only holds when:
, and
is odd
For example:
If , then:
✅ (odd )
❌ (even )
So this algorithm is only valid when both conditions are met.
Last updated