galois.gcd¶
-
galois.
gcd
(a, b)[source]¶ Finds the integer multiplicands of \(a\) and \(b\) such that \(a x + b y = \mathrm{gcd}(a, b)\).
This implementation uses the Extended Euclidean Algorithm.
- Parameters
- Returns
int – Greatest common divisor of \(a\) and \(b\).
int – Integer \(x\), such that \(a x + b y = \mathrm{gcd}(a, b)\).
int – Integer \(y\), such that \(a x + b y = \mathrm{gcd}(a, b)\).
References
Moon, “Error Correction Coding”, Section 5.2.2: The Euclidean Algorithm and Euclidean Domains, p. 181
https://en.wikipedia.org/wiki/Euclidean_algorithm#Extended_Euclidean_algorithm
Examples
In [1]: a = 2 In [2]: b = 13 In [3]: gcd, x, y = galois.gcd(a, b) In [4]: gcd, x, y Out[4]: (1, -6, 1) In [5]: a*x + b*y == gcd Out[5]: True