/// <summary> /// Calculates the multiplicative inverse of <c>this</c> and returns the result in a new GF2nPolynomialElement /// </summary> /// /// <returns>Returns <c>this</c>^(-1)</returns> public GF2nPolynomialElement InvertEEA() { if (IsZero()) { throw new ArithmeticException(); } GF2Polynomial b = new GF2Polynomial(mDegree + 32, "ONE"); b.ReduceN(); GF2Polynomial c = new GF2Polynomial(mDegree + 32); c.ReduceN(); GF2Polynomial u = GetGF2Polynomial(); GF2Polynomial v = mField.FieldPolynomial; GF2Polynomial h; int j; u.ReduceN(); while (!u.IsOne()) { u.ReduceN(); v.ReduceN(); j = u.Length - v.Length; if (j < 0) { h = u; u = v; v = h; h = b; b = c; c = h; j = -j; c.ReduceN(); // this increases the performance } u.ShiftLeftAddThis(v, j); b.ShiftLeftAddThis(c, j); } b.ReduceN(); return(new GF2nPolynomialElement((GF2nPolynomialField)mField, b)); }
/// <summary> /// Calculates the multiplicative inverse of <c>this</c> and returns the result in a new GF2nPolynomialElement /// </summary> /// /// <returns>Returns <c>this</c>^(-1)</returns> public GF2nPolynomialElement InvertEEA() { if (IsZero()) throw new ArithmeticException(); GF2Polynomial b = new GF2Polynomial(mDegree + 32, "ONE"); b.ReduceN(); GF2Polynomial c = new GF2Polynomial(mDegree + 32); c.ReduceN(); GF2Polynomial u = GetGF2Polynomial(); GF2Polynomial v = mField.FieldPolynomial; GF2Polynomial h; int j; u.ReduceN(); while (!u.IsOne()) { u.ReduceN(); v.ReduceN(); j = u.Length - v.Length; if (j < 0) { h = u; u = v; v = h; h = b; b = c; c = h; j = -j; c.ReduceN(); // this increases the performance } u.ShiftLeftAddThis(v, j); b.ShiftLeftAddThis(c, j); } b.ReduceN(); return new GF2nPolynomialElement((GF2nPolynomialField)mField, b); }