Cipolla's algorithm

Last updated

In computational number theory, Cipolla's algorithm is a technique for solving a congruence of the form

Contents

where , so n is the square of x, and where is an odd prime. Here denotes the finite field with elements; . The algorithm is named after Michele Cipolla, an Italian mathematician who discovered it in 1907.

Apart from prime moduli, Cipolla's algorithm is also able to take square roots modulo prime powers. [1]

Algorithm

Inputs:

Outputs:

Step 1 is to find an such that is not a square. There is no known deterministic algorithm for finding such an , but the following trial and error method can be used. Simply pick an and by computing the Legendre symbol one can see whether satisfies the condition. The chance that a random will satisfy is . With large enough this is about . [2] Therefore, the expected number of trials before finding a suitable is about 2.

Step 2 is to compute x by computing within the field extension . This x will be the one satisfying

If , then also holds. And since p is odd, . So whenever a solution x is found, there's always a second solution, -x.

Example

(Note: All elements before step two are considered as an element of and all elements in step two are considered as elements of .)

Find all x such that

Before applying the algorithm, it must be checked that is indeed a square in . Therefore, the Legendre symbol has to be equal to 1. This can be computed using Euler's criterion: This confirms 10 being a square and hence the algorithm can be applied.

So is a solution, as well as . Indeed,

Proof

The first part of the proof is to verify that is indeed a field. For the sake of notation simplicity, is defined as . Of course, is a quadratic non-residue, so there is no square root in . This can roughly be seen as analogous to the complex number i. The field arithmetic is quite obvious. Addition is defined as

.

Multiplication is also defined as usual. With keeping in mind that , it becomes

.

Now the field properties have to be checked. The properties of closure under addition and multiplication, associativity, commutativity and distributivity are easily seen. This is because in this case the field is somewhat resembles the field of complex numbers (with being the analogon of i).
The additive identity is , or more formally : Let , then

.

The multiplicative identity is , or more formally :

.

The only thing left for being a field is the existence of additive and multiplicative inverses. It is easily seen that the additive inverse of is , which is an element of , because . In fact, those are the additive inverse elements of x and y. For showing that every non-zero element has a multiplicative inverse, write down and . In other words,

.

So the two equalities and must hold. Working out the details gives expressions for and , namely

,
.

The inverse elements which are shown in the expressions of and do exist, because these are all elements of . This completes the first part of the proof, showing that is a field.

The second and middle part of the proof is showing that for every element . By definition, is not a square in . Euler's criterion then says that

.

Thus . This, together with Fermat's little theorem (which says that for all ) and the knowledge that in fields of characteristic p the equation holds, a relationship sometimes called the Freshman's dream, shows the desired result

.

The third and last part of the proof is to show that if , then .
Compute

.

Note that this computation took place in , so this . But with Lagrange's theorem, stating that a non-zero polynomial of degree n has at most n roots in any field K, and the knowledge that has 2 roots in , these roots must be all of the roots in . It was just shown that and are roots of in , so it must be that . [3]

Speed

After finding a suitable a, the number of operations required for the algorithm is multiplications, sums, where m is the number of digits in the binary representation of p and k is the number of ones in this representation. To find a by trial and error, the expected number of computations of the Legendre symbol is 2. But one can be lucky with the first try and one may need more than 2 tries. In the field , the following two equalities hold

where is known in advance. This computation needs 4 multiplications and 4 sums.

where and . This operation needs 6 multiplications and 4 sums.

Assuming that (in the case , the direct computation is much faster) the binary expression of has digits, of which k are ones. So for computing a power of , the first formula has to be used times and the second times.

For this, Cipolla's algorithm is better than the Tonelli–Shanks algorithm if and only if , with being the maximum power of 2 which divides . [4]

Prime power moduli

According to Dickson's "History Of Numbers", the following formula of Cipolla will find square roots modulo powers of prime: [5] [6]

where and
where , as in this article's example

Taking the example in the wiki article we can see that this formula above does indeed take square roots modulo prime powers.

As

Now solve for via:

Now create the and (See here for mathematica code showing this above computation, remembering that something close to complex modular arithmetic is going on here)

As such:

and

and the final equation is:

which is the answer.

Related Research Articles

<span class="mw-page-title-main">Chinese remainder theorem</span> Theorem for solving simultaneous congruences

In mathematics, the Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.

<span class="mw-page-title-main">Discrete Fourier transform</span> Type of Fourier transform in discrete mathematics

In mathematics, the discrete Fourier transform (DFT) converts a finite sequence of equally-spaced samples of a function into a same-length sequence of equally-spaced samples of the discrete-time Fourier transform (DTFT), which is a complex-valued function of frequency. The interval at which the DTFT is sampled is the reciprocal of the duration of the input sequence. An inverse DFT (IDFT) is a Fourier series, using the DTFT samples as coefficients of complex sinusoids at the corresponding DTFT frequencies. It has the same sample-values as the original input sequence. The DFT is therefore said to be a frequency domain representation of the original input sequence. If the original sequence spans all the non-zero values of a function, its DTFT is continuous, and the DFT provides discrete samples of one cycle. If the original sequence is one cycle of a periodic function, the DFT provides all the non-zero values of one DTFT cycle.

In number theory, the Legendre symbol is a multiplicative function with values 1, −1, 0 that is a quadratic character modulo of an odd prime number p: its value at a (nonzero) quadratic residue mod p is 1 and at a non-quadratic residue (non-residue) is −1. Its value at zero is 0.

<span class="mw-page-title-main">Quadratic reciprocity</span> Gives conditions for the solvability of quadratic equations modulo prime numbers

In number theory, the law of quadratic reciprocity is a theorem about modular arithmetic that gives conditions for the solvability of quadratic equations modulo prime numbers. Due to its subtlety, it has many formulations, but the most standard statement is:

In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers. The test was originally developed by Édouard Lucas in 1878 and subsequently proved by Derrick Henry Lehmer in 1930.

The quadratic sieve algorithm (QS) is an integer factorization algorithm and, in practice, the second-fastest method known. It is still the fastest for integers under 100 decimal digits or so, and is considerably simpler than the number field sieve. It is a general-purpose factorization algorithm, meaning that its running time depends solely on the size of the integer to be factored, and not on special structure or properties. It was invented by Carl Pomerance in 1981 as an improvement to Schroeppel's linear sieve.

In number theory, the Kronecker symbol, written as or , is a generalization of the Jacobi symbol to all integers . It was introduced by Leopold Kronecker.

In number theory, Dixon's factorization method is a general-purpose integer factorization algorithm; it is the prototypical factor base method. Unlike for other factor base methods, its run-time bound comes with a rigorous proof that does not rely on conjectures about the smoothness properties of the values taken by a polynomial.

<span class="mw-page-title-main">Schönhage–Strassen algorithm</span> Multiplication algorithm

The Schönhage–Strassen algorithm is an asymptotically fast multiplication algorithm for large integers, published by Arnold Schönhage and Volker Strassen in 1971. It works by recursively applying fast Fourier transform (FFT) over the integers modulo 2n+1. The run-time bit complexity to multiply two n-digit numbers using the algorithm is in big O notation.

In mathematics, Hensel's lemma, also known as Hensel's lifting lemma, named after Kurt Hensel, is a result in modular arithmetic, stating that if a univariate polynomial has a simple root modulo a prime number p, then this root can be lifted to a unique root modulo any higher power of p. More generally, if a polynomial factors modulo p into two coprime polynomials, this factorization can be lifted to a factorization modulo any higher power of p.

In algebraic number theory, the narrow class group of a number field K is a refinement of the class group of K that takes into account some information about embeddings of K into the field of real numbers.

The Tonelli–Shanks algorithm is used in modular arithmetic to solve for r in a congruence of the form r2n, where p is a prime: that is, to find a square root of n modulo p.

In mathematics, a Witt vector is an infinite sequence of elements of a commutative ring. Ernst Witt showed how to put a ring structure on the set of Witt vectors, in such a way that the ring of Witt vectors over the finite field of order is isomorphic to , the ring of -adic integers. They have a highly non-intuitive structure upon first glance because their additive and multiplicative structure depends on an infinite set of recursive formulas which do not behave like addition and multiplication formulas for standard p-adic integers.

In cryptography, the Rabin signature algorithm is a method of digital signature originally proposed by Michael O. Rabin in 1978.

Cubic reciprocity is a collection of theorems in elementary and algebraic number theory that state conditions under which the congruence x3 ≡ p (mod q) is solvable; the word "reciprocity" comes from the form of the main theorem, which states that if p and q are primary numbers in the ring of Eisenstein integers, both coprime to 3, the congruence x3p is solvable if and only if x3q is solvable.

In mathematics, elliptic curve primality testing techniques, or elliptic curve primality proving (ECPP), are among the quickest and most widely used methods in primality proving. It is an idea put forward by Shafi Goldwasser and Joe Kilian in 1986 and turned into an algorithm by A. O. L. Atkin the same year. The algorithm was altered and improved by several collaborators subsequently, and notably by Atkin and François Morain, in 1993. The concept of using elliptic curves in factorization had been developed by H. W. Lenstra in 1985, and the implications for its use in primality testing followed quickly.

Pocklington's algorithm is a technique for solving a congruence of the form

The quantization of electromagnetic Radiation means that electromagnetic radiation consists of discrete energy parcels called photons. Photons are massless particles of definite energy, definite momentum, and definite spin.

Coppersmith's attack describes a class of cryptographic attacks on the public-key cryptosystem RSA based on the Coppersmith method. Particular applications of the Coppersmith method for attacking RSA include cases when the public exponent e is small or when partial knowledge of a prime factor of the secret key is available.

Kunerth's algorithm is an algorithm for computing the modular square root of a given number. 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.

References

  1. Dickson, Leonard Eugene (1919). History of the Theory of Numbers. Vol. 1. p. 218.
  2. R. Crandall, C. Pomerance Prime Numbers: A Computational Perspective Springer-Verlag, (2001) p. 157
  3. "M. Baker Cipolla's Algorithm for finding square roots mod p" (PDF). Archived from the original (PDF) on 2017-03-25. Retrieved 2011-08-24.
  4. Tornaría, Gonzalo (2002). "Square Roots Modulo P". LATIN 2002: Theoretical Informatics. Lecture Notes in Computer Science. Vol. 2286. pp. 430–434. doi:10.1007/3-540-45995-2_38. ISBN   978-3-540-43400-9.
  5. "History of the Theory of Numbers" Volume 1 by Leonard Eugene Dickson, p218, Chelsea Publishing 1952 read online
  6. Michelle Cipolla, Rendiconto dell' Accademia delle Scienze Fisiche e Matematiche. Napoli, (3),10,1904, 144-150

Sources