Euclidean algorithm

From Maths
Jump to: navigation, search

Note: this is an algorithm for computing the GCD of two positive integers

Definition

The algorithm is as follows[1]:

Input [ilmath]a,b\in\mathbb{N}_+[/ilmath], such that [ilmath]a\ge b[/ilmath] (swap them around if [ilmath]a< b[/ilmath])
Output The GCD of [ilmath]a[/ilmath] and [ilmath]b[/ilmath]
Process
  1. Let [ilmath]A=a[/ilmath]
  2. Let [ilmath]B=b[/ilmath]
  3. Let [ilmath]R=[/ilmath] the remainder of [ilmath]A\div B[/ilmath] (see Division algorithm)
  4. If [ilmath]R=0[/ilmath] then:
    1. RETURN: [ilmath]B[/ilmath] (we have [ilmath]B=\text{gcd}(a,b)[/ilmath])
  5. Let [ilmath]A=B[/ilmath]
  6. Let [ilmath]B=R[/ilmath]
  7. Goto step 3

Proofs of correctness


TODO: These proofs


The algorithm terminates

Given this algorithm loops until [ilmath]R=0[/ilmath] it is important to know for certain that eventually we will have [ilmath]R=0[/ilmath]

The algorithm computes the GCD

Equally important is the proof that the algorithm always outputs the GCD of [ilmath]a[/ilmath] and [ilmath]b[/ilmath]


See next

See also

References

  1. The mathematics of ciphers, Number theory and RSA cryptography - S. C. Coutinho