/// <summary> /// Compute the square root of this element /// </summary> public override void SquareRootThis() { // increase performance polynomial.ExpandN((mDegree << 1) + 32); polynomial.ReduceN(); for (int i = 0; i < mField.Degree - 1; i++) { SquareThis(); } }
/// <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> using the modified almost inverse algorithm and returns the result in a new GF2nPolynomialElement /// </summary> /// /// <returns>Returns <c>this</c>^(-1)</returns> public GF2nPolynomialElement InvertMAIA() { if (IsZero()) { throw new ArithmeticException(); } GF2Polynomial b = new GF2Polynomial(mDegree, "ONE"); GF2Polynomial c = new GF2Polynomial(mDegree); GF2Polynomial u = GetGF2Polynomial(); GF2Polynomial v = mField.FieldPolynomial; GF2Polynomial h; while (true) { while (!u.TestBit(0)) { // x|u (x divides u) u.ShiftRightThis(); // u = u / x if (!b.TestBit(0)) { b.ShiftRightThis(); } else { b.AddToThis(mField.FieldPolynomial); b.ShiftRightThis(); } } if (u.IsOne()) { return(new GF2nPolynomialElement((GF2nPolynomialField)mField, b)); } u.ReduceN(); v.ReduceN(); if (u.Length < v.Length) { h = u; u = v; v = h; h = b; b = c; c = h; } u.AddToThis(v); b.AddToThis(c); } }
/// <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); }