- galois.gcd(a: int, b: int) int
- galois.gcd(a: Poly, b: Poly) Poly
Finds the greatest common divisor of
and .Notes¶
This function implements the Euclidean Algorithm.
References¶
Algorithm 2.104 from https://cacr.uwaterloo.ca/hac/about/chap2.pdf
Algorithm 2.218 from https://cacr.uwaterloo.ca/hac/about/chap2.pdf
Examples¶
Compute the GCD of two integers.
In [1]: galois.gcd(12, 16) Out[1]: 4
Generate irreducible polynomials over
.In [2]: GF = galois.GF(7) In [3]: f1 = galois.irreducible_poly(7, 1); f1 Out[3]: Poly(x, GF(7)) In [4]: f2 = galois.irreducible_poly(7, 2); f2 Out[4]: Poly(x^2 + 1, GF(7)) In [5]: f3 = galois.irreducible_poly(7, 3); f3 Out[5]: Poly(x^3 + 2, GF(7))
Compute the GCD of
and , which is .In [6]: galois.gcd(f1**2 * f2, f1 * f3) Out[6]: Poly(x, GF(7))