/// <summary> /// Checks if <c>this</c> is irreducible, according to IEEE P1363, A.5.5, p103. /// <para>Note: The algorithm from IEEE P1363, A5.5 can be used to check a polynomial with coefficients in GF(2^r) for irreducibility. /// As this class only represents polynomials with coefficients in GF(2), the algorithm is adapted to the case r=1.</para> /// </summary> /// /// <returns>Returns true if <c>this</c> is irreducible</returns> public bool IsIrreducible() { if (IsZero()) return false; GF2Polynomial f = new GF2Polynomial(this); int d, i; GF2Polynomial u, g; GF2Polynomial dummy; f.ReduceN(); d = f._length - 1; u = new GF2Polynomial(f._length, "X"); for (i = 1; i <= (d >> 1); i++) { u.SquareThisPreCalc(); u = u.Remainder(f); dummy = u.Add(new GF2Polynomial(32, "X")); if (!dummy.IsZero()) { g = f.Gcd(dummy); if (!g.IsOne()) return false; } else { return false; } } return true; }
/// <summary> /// Returns the greatest common divisor of <c>this</c> and <c>G</c> in a new GF2Polynomial /// </summary> /// /// <param name="G">A GF2Polynomial != 0</param> /// /// <returns>Returns a new GF2Polynomial gcd(<c>this</c>,<c>g</c>)</returns> public GF2Polynomial Gcd(GF2Polynomial G) { if (IsZero() && G.IsZero()) throw new ArithmeticException("Both operands of gcd equal zero."); if (IsZero()) return new GF2Polynomial(G); if (G.IsZero()) return new GF2Polynomial(this); GF2Polynomial a = new GF2Polynomial(this); GF2Polynomial b = new GF2Polynomial(G); GF2Polynomial c; while (!b.IsZero()) { c = a.Remainder(b); a = b; b = c; } return a; }