/// <summary> /// Create a finite field GF(2^m) /// </summary> /// /// <param name="Degree">The degree of the field</param> public GF2mField(int Degree) { if (Degree >= 32) { throw new ArgumentException("Error: the degree of field is too large!"); } if (Degree < 1) { throw new ArgumentException("Error: the degree of field is non-positive!"); } this._degree = Degree; _polynomial = PolynomialRingGF2.GetIrreduciblePolynomial(Degree); }
/// <summary> /// Create a finite field GF(2^m) with the fixed field polynomial /// </summary> /// /// <param name="Degree">The degree of the field</param> /// <param name="Polynomial">The field polynomial</param> public GF2mField(int Degree, int Polynomial) { if (Degree != PolynomialRingGF2.Degree(Polynomial)) { throw new ArgumentException(" Error: the degree is not correct!"); } if (!PolynomialRingGF2.IsIrreducible(Polynomial)) { throw new ArgumentException(" Error: given polynomial is reducible!"); } _degree = Degree; _polynomial = Polynomial; }
/// <summary> /// Create a finite field GF(2^m) using an encoded array /// </summary> /// /// <param name="Encoded">The polynomial and degree encoded as a byte array</param> public GF2mField(byte[] Encoded) { if (Encoded.Length != 4) { throw new ArgumentException("byte array is not an encoded finite field"); } _polynomial = LittleEndian.OctetsToInt(Encoded); if (!PolynomialRingGF2.IsIrreducible(_polynomial)) { throw new ArgumentException("byte array is not an encoded finite field"); } _degree = PolynomialRingGF2.Degree(_polynomial); }
/// <summary> /// Return the product of two elements /// </summary> /// /// <param name="A">Integer value A</param> /// <param name="B">Integer value b</param> /// /// <returns>The sum: <c>a*b</c></returns> public int Multiply(int A, int B) { return(PolynomialRingGF2.ModMultiply(A, B, _polynomial)); }