The Extended Euclidean Algorithm is a fundamental mathematical tool in the field of number theory, which finds extensive application in public-key cryptography. It is an enhancement of the classical Euclidean Algorithm, which is used to compute the greatest common divisor (GCD) of two integers. The extended version not only computes the GCD but also finds the coefficients of Bézout's identity, which are integers
and
such that for given integers
and
:
![]()
This property is particularly useful in cryptographic applications, such as the RSA algorithm, where modular inverses are required.
Euclidean Algorithm Recap
To appreciate the extended version, one must first understand the classical Euclidean Algorithm. The Euclidean Algorithm is based on the principle that the GCD of two numbers also divides their difference. The algorithm can be described by the following recursive procedure:
1. Given two integers
and
where
, compute the remainder
of the division of
by
.
2. Replace
with
and
with
.
3. Repeat the process until
becomes zero. The non-zero remainder at this stage will be the GCD of the original pair of integers.
Mathematically, this can be represented as:
![]()
Extended Euclidean Algorithm
The Extended Euclidean Algorithm builds upon this by keeping track of additional coefficients that express the GCD as a linear combination of the original integers
and
. The steps involved are:
1. Initialize:
![]()
These are the coefficients for the initial values of
and
.
2. Perform the Euclidean Algorithm while updating the coefficients:
![]()
For each iteration
, compute:
![]()
Update the remainders:
![]()
Update the coefficients:
![]()
3. Continue this process until
. At this point,
will be the GCD of
and
, and the coefficients
and
will satisfy:
![]()
Example
Consider the integers
and
. The goal is to find the GCD of these numbers and express it as a linear combination of 30 and 20.
1. Apply the Euclidean Algorithm:
![]()
The GCD is 10.
2. Use the Extended Euclidean Algorithm:
![]()
First iteration:
![Rendered by QuickLaTeX.com \[ <span class="ql-right-eqno"> </span><span class="ql-left-eqno"> </span><img src="https://eitca.org/wp-content/ql-cache/quicklatex.com-a5aabe301eddd6f1101aef77673f66d5_l3.png" height="122" width="162" class="ql-img-displayed-equation quicklatex-auto-format" alt="\begin{align*} q_1 &= \left\lfloor \frac{30}{20} \right\rfloor = 1 \\ r_2 &= 30 - 1 \cdot 20 = 10 \\ x_2 &= 1 - 1 \cdot 0 = 1 \\ y_2 &= 0 - 1 \cdot 1 = -1 \\ \end{align*}" title="Rendered by QuickLaTeX.com"/> \]](https://eitca.org/wp-content/ql-cache/quicklatex.com-303f30b72c13e7143861d5fd5ea62002_l3.png)
Second iteration:
![Rendered by QuickLaTeX.com \[ <span class="ql-right-eqno"> </span><span class="ql-left-eqno"> </span><img src="https://eitca.org/wp-content/ql-cache/quicklatex.com-30b7e8c1705a5f7cfb752b8eecec8d80_l3.png" height="123" width="162" class="ql-img-displayed-equation quicklatex-auto-format" alt="\begin{align*} q_2 &= \left\lfloor \frac{20}{10} \right\rfloor = 2 \\ r_3 &= 20 - 2 \cdot 10 = 0 \\ x_3 &= 0 - 2 \cdot 1 = -2 \\ y_3 &= 1 - 2 \cdot (-1) = 3 \\ \end{align*}" title="Rendered by QuickLaTeX.com"/> \]](https://eitca.org/wp-content/ql-cache/quicklatex.com-602b174b6a392eb349d3c5d8b86d9ed2_l3.png)
At this point,
is the GCD, and the coefficients are
and
. Thus, we have:
![]()
Application in Public-Key Cryptography
One of the critical applications of the Extended Euclidean Algorithm in public-key cryptography is in the RSA algorithm, particularly in finding the modular inverse. In RSA, the private key
is the modular inverse of
modulo
, where
is Euler's totient function. Specifically,
must satisfy:
![]()
This is equivalent to finding
such that:
![]()
for some integer
. Using the Extended Euclidean Algorithm, we can find
and
efficiently.
Python Implementation
Here is a Python implementation of the Extended Euclidean Algorithm:
python
def extended_gcd(a, b):
if a == 0:
return b, 0, 1
gcd, x1, y1 = extended_gcd(b % a, a)
x = y1 - (b // a) * x1
y = x1
return gcd, x, y
# Example usage
a = 30
b = 20
gcd, x, y = extended_gcd(a, b)
print(f"GCD: {gcd}, x: {x}, y: {y}")
This function recursively computes the GCD and the coefficients
and
. When run with
and
, it outputs:
![]()
The Extended Euclidean Algorithm is a powerful extension of the classical Euclidean Algorithm, providing not only the GCD of two integers but also the coefficients of Bézout's identity. This capability is important in various cryptographic applications, particularly in computing modular inverses needed for algorithms like RSA. Understanding and implementing this algorithm is fundamental for anyone involved in the field of public-key cryptography and number theory.
Other recent questions and answers regarding Number theory for PKC – Euclidean Algorithm, Euler’s Phi Function and Euler’s Theorem:
- What does Fermat’s Little Theorem state?
- What is EEA ?
- Can public key be used for authentication if the asymmetric relation in terms of complexity in computing keys is reversed?
- What are eulers theorem used for?
- What are eulers theorem used for?
- Can a private key be computed from public key?
- What is a public key?
- What is a public key?
- What is the parameter t of the extended eulers algoritm?
- What is an extended eulers algorithm?

