Euclidean Algorithm
Introduction
Most of the modern cryptosystems were developed based on the fact that it is extremely inefficient to factoring large composite numbers, usually in exponential complexity. Therefore, breaking these cryptosystems have been extremely hard. With a quantum computer, the quantum Shor’s algorithm is able to factorize large composite numbers in polynomial complexity. However, the Shor’s algorithm does have a fraction that uses classical algorithm to find the greatest common divisor of two integers. The most efficient classical algorithms to find the greatest common divisor of two integers is Euclidean algorithm and its variants.
In this blog post, I would like to discuss the Euclidean algorithm and systematically prove its usefulness.
Prerequisites
Greatest Common Divisor Reduction
Let
Proof
Suppose
for some
This means that any common divisor for
Similarly, we could prove that any common divisor for
Because
This concludes the proof.
Fibonacci Sequence
The numbers in the Fibonacci sequence,
for integer
The Fibonacci sequence has a property that is useful for proving the usefulness of the Euclidean algorithm.
Proof
We could prove this property using strong induction. Let
Basis Step: it is easy to verify that
Induction Step: Assume
Because
Because of the induction hypothesis, we have
Therefore,
Therefore,
Euclidean Algorithm
Based on the property of the greatest common divisor reduction in the prerequisites, the greatest common divisor problem could be solved recursively. Instead of using recursively function, we implemented the function in a iterative manner.
Euclidean Algorithm Pseudocode
When the remainder
It does not matter if
One might ask why the remainder
Euclidean Algorithm Implementation
1 | #include <iostream> |
Lamé’s Theorem
Let
Proof
Suppose the Euclidean algorithm is applied to find
We initialize
There must exist an ending condition where
Note that the quotients
where
Using the special property of Fibonacci sequence we have just proved in the prerequisites section,
Furthermore, because
Thus, we have
We further have
where
Asymptotic Complexity
Based on the Lamé’s theorem, the asymptotic complexity for the Euclidean algorithm to compute
Euclidean Algorithm Variants
There are Euclidean algorithm variants, such as the extended Euclidean algorithm, which are actually used in practice instead of the vanilla Euclidean algorithm, due to their efficiency in computation. However, since they don’t improve the asymptotic complexity compared to the vanilla Euclidean algorithm, we are not going into the details for the moment.
References
Euclidean Algorithm