Given two non-negative integers, find the greatest common divisor (GCD) along with the coefficients of Bézout’s identity (x and y such that ax + by = gcd(a, b)) using the Extended Euclidean algorithm with the modulo operator.
The Extended Euclidean Algorithm extends the basic Euclidean algorithm to find not just the GCD but also the coefficients (x and y) for Bézout’s identity.
The extended Euclidean algorithm refines the results of gcd(a, b) by employing the results from the recursive call gcd(b % a, a). If x1 and y1 are derived from this recursive call, then x and y are updated as follows:
The extended Euclidean algorithm is highly effective when a and b are coprime, i.e., their gcd is 1. In this algorithm, x serves as the modular multiplicative inverse of a modulo b, and y is the modular multiplicative inverse of b modulo a. Calculating the modular multiplicative inverse is a crucial part of the RSA public-key encryption process.