Jump to content

Tonelli–Shanks algorithm

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Robost (talk | contribs) at 15:19, 9 January 2006 (Created page, after implementing and testing the algorithm (source of the algorithm: the web page linked to).). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

The Shanks-Tonelli algorithm is used within modular arithmetic to solve a congruence of the form , where n is a quadratic residue (mod p), and typically .

When , it is much more efficient to use the following identity: .

The algorithm

Inputs: p, an odd prime. n, an integer which is a quadratic residue (mod p), meaning that the Legendre symbol (n/p) = 1.

Outputs: R, an integer satisfying .

  1. Factor out powers of 2 from (p-1), defining Q and S as: .
  2. Select a W such that the Legendre symbol (W/p) = -1 (that is, W should be a quadratic non-residue modulo p).
  3. Let .
  4. Let .
    1. Loop:
    2. Find the smallest i, , such that . This can be done efficiently by starting with and squaring (mod p) until the result is 1.
    3. If , return R.
    4. Otherwise, let and repeat the loop with R' as the new R.

Uses

Modular square roots are used in, for example, the quadratic sieve and related integer factoring algorithms.

Quadratic Sieve Algorithm - contains a description of the Shanks-Tonelli algorithm.