Extended Euclidean Algorithm Algorithm

In arithmetical and computer programming, the extended euclidean algorithm is an extension to the euclidean algorithm, and computes, in addition to the greatest common divisor of integers a and b, also the coefficients of Bézout's identity, which are integers X and Y such that with that provision, X is the modular multiplicative inverse of a modulo b, and Y is the modular multiplicative inverse of b modulo a. Similarly, the polynomial extended euclidean algorithm lets one to calculate the multiplicative inverse in algebraic field extensions and, in particular in finite fields of non prime order.

Extended Euclidean Algorithm source code, pseudocode and analysis