Kunerth's algorithm

Kunerth's algorithm is an algorithm for computing the modular square root of a given number.[1][2] The algorithm does not require the factorization of the modulus, and relies on modular operations that is often easy when the given number is prime.

Algorithm

To find y from a given value

B = y 2 mod N , {\displaystyle B=y^{2}{\bmod {N}},}

it takes the following steps:

  1. find the modular square root of r ± N ( mod B ) {\displaystyle r\equiv {\sqrt {\pm N}}{\pmod {B}}} . This step is quite easy, irrespectively of how big N when B {\displaystyle B} is a prime.
  2. solve a quadratic equation associated with the modular square root of w 2 = A z 2 + B z + C {\displaystyle w^{2}=A\cdot z^{2}+B\cdot z+C} . Most of Kunerth's examples in his original paper solve this equation by having C be a integer square and thus setting z to zero.
    Expand out the following equation to obtain the quadratic
    ( ( B z + r ) 2 ± N ) / B = w 2 . {\displaystyle ((B\cdot z+r)^{2}\pm N)/B=w^{2}.}
    One can always make sure that the quadratic can be solved by adjusting the modulus N in the above equation. Thus
    ( ( B z + r ) 2 + ( B F + N ) ) / B = w 2 {\displaystyle ((B\cdot z+r)^{2}+(B\cdot F+N))/B=w^{2}}
    will ensure a quadratic of A z 2 + D z + C + F {\displaystyle A\cdot z^{2}+D\cdot z+C+F} .
    One can then adjust F to make sure that C + F {\displaystyle C+F} is a square. For large moduli, such as 67 mod 67 F + R S A 260 {\displaystyle {\sqrt {67}}{\bmod {67F+RSA260}}} , can have their square roots computed quickly via this method.
    The parameters of the polynomial expansion are quite flexible, in that ( ( 67 z + r ) 2 + X R S A 260 ) / ( 67 y ) {\displaystyle ((67z+r)^{2}+X\cdot RSA260)/(67y)} can be done, for instance. It is quite easy to choose X and Y such that ( r 2 + X R S A 260 ) / ( 67 y ) {\displaystyle (r^{2}+X\cdot RSA260)/(67y)} is a square. The modular square root of 67 y mod R S A 260 {\displaystyle {\sqrt {67y}}{\bmod {RSA260}}} can be taken this way.
  3. Having solved the associated quadratic equation we now have the variables w and set v = r (if C in the quadratic is a natural square).
  4. Solve for variables α {\displaystyle \alpha } and β {\displaystyle \beta } the following equation:
    α = w ( v + w β ) , {\displaystyle \alpha =w(v+w\beta ),}
  5. Obtain a value for X via factorization of the following polynomial:
    α 2 x 2 + ( 2 α β N ) x + ( β 2 ( y 2 mod N ) ) {\displaystyle \alpha ^{2}\cdot x^{2}+(2\alpha \beta -N)x+(\beta ^{2}-(y^{2}{\bmod {N}}))}
    obtaining an answer like
    ( 37 + 9 x ) ( 1 + 25 x ) {\displaystyle (-37+9x)(1+25x)}
  6. Obtain the modular square root by the equation. Remember to set X such that the term above is zero. Thus X would be 37/9 or -1/25.
    y α X + β ( mod N ) . {\displaystyle y\equiv \alpha X+\beta {\pmod {N}}.}

Example

To obtain 41 mod 856 , {\displaystyle {\sqrt {41}}{\bmod {856}},} first obtain 856 13 ( mod 41 ) {\displaystyle {\sqrt {-856}}\equiv 13{\pmod {41}}} .

Then expand the polynomial:

( ( 41 z + 13 ) 2 + 856 ) / 41 = w 2 {\displaystyle ((41z+13)^{2}+856)/41=w^{2}}

into

25 + 26 z + 41 z 2 {\displaystyle 25+26z+41z^{2}}

Since, in this case the C term is a square, we take w = 5 {\displaystyle w=5} and compute v = 13 {\displaystyle v=13} (in general, v = 41 z + 13 {\displaystyle v=41\cdot z+13} ).

Solve for α {\displaystyle \alpha } and β {\displaystyle \beta } the following equation
α == w ( v + w β ) {\displaystyle \alpha ==w(v+w\beta )}
getting the solution α = 15 {\displaystyle \alpha =15} and β = 2 {\displaystyle \beta =-2} . (There may be other pairs of solutions to this equation.)
Then factor the following polynomial:
α 2 x 2 + ( 2 α β 856 ) x + ( β 2 41 ) {\displaystyle \alpha ^{2}x^{2}+(2\alpha \beta -856)x+(\beta ^{2}-41)}
obtaining
( 37 + 9 x ) ( 1 + 25 x ) {\displaystyle (-37+9x)(1+25x)}
Then obtain the modular square root via
15 ( 37 9 1 ) + ( 2 ) 345 ( mod 856 ) . {\displaystyle 15\cdot (37\cdot 9^{-1})+(-2)\equiv 345{\pmod {856}}.}
Verify that 345 2 41 ( mod 856 ) . {\displaystyle 345^{2}\equiv 41{\pmod {856}}.}

In the case that 856 mod 41 {\displaystyle {\sqrt {-856}}{\bmod {41}}} has no answer, then r 856 ( mod b 856 + 41 ) {\displaystyle r\equiv {\sqrt {-856}}{\pmod {b\cdot 856+41}}} can be used instead.

See also

References

  1. ^ Adolf Kunerth, "Sitzungsberichte. Academie Der Wissenschaften" vol 78(2), 1878, p 327-338 (for quadratic equation algorithm), pp. 338–346 (for modular quadratic algorithm), available at Ernest Mayr Library, Harvard University
  2. ^ Leonard Eugene Dickson, "History of Numbers", vol 2, pp. 382–384.
  • Adolf Kunerth, "Sitzungsberichte. Academie Der Wissenschaften" vol 75, II, 1877, pp. 7–58
  • Adolf Kunerth, "Sitzungsberichte. Academie Der Wissenschaften" vol 82, II, 1880, pp. 342–375
  • v
  • t
  • e
Number-theoretic algorithms
Primality tests
Prime-generatingInteger factorizationMultiplicationEuclidean divisionDiscrete logarithmGreatest common divisorModular square rootOther algorithms
  • Italics indicate that algorithm is for numbers of special forms