/// <summary>
 /// Computes the field polynomial for a ONB according to IEEE 1363 A.7.2
 /// </summary>
 protected override void ComputeFieldPolynomial()
 {
     if (_mType == 1)
     {
         FieldPoly = new GF2Polynomial(DegreeN + 1, "ALL");
     }
     else if (_mType == 2)
     {
         // 1. q = 1
         GF2Polynomial q = new GF2Polynomial(DegreeN + 1, "ONE");
         // 2. p = t+1
         GF2Polynomial p = new GF2Polynomial(DegreeN + 1, "X");
         p.AddToThis(q);
         GF2Polynomial r;
         int i;
         // 3. for i = 1 to (m-1) do
         for (i = 1; i < DegreeN; i++)
         {
             // r <- q
             r = q;
             // q <- p
             q = p;
             // p = tq+r
             p = q.ShiftLeft();
             p.AddToThis(r);
         }
         FieldPoly = p;
     }
 }
        /// <summary>
        /// Returns the absolute quotient of <c>this</c> divided by <c>G</c> in a new GF2Polynomial
        /// </summary>
        /// 
        /// <param name="G">A GF2Polynomial != 0</param>
        /// 
        /// <returns>Returns a new GF2Polynomial |_ <c>this</c> / <c>G</c></returns>
        public GF2Polynomial Quotient(GF2Polynomial G)
        {
            // a div b = q / r
            GF2Polynomial q = new GF2Polynomial(_length);
            GF2Polynomial a = new GF2Polynomial(this);
            GF2Polynomial b = new GF2Polynomial(G);
            GF2Polynomial j;
            int i;

            if (b.IsZero())
                throw new Exception();

            a.ReduceN();
            b.ReduceN();
            if (a._length < b._length)
                return new GF2Polynomial(0);

            i = a._length - b._length;
            q.ExpandN(i + 1);

            while (i >= 0)
            {
                j = b.ShiftLeft(i);
                a.SubtractFromThis(j);
                a.ReduceN();
                q.XorBit(i);
                i = a._length - b._length;
            }

            return q;
        }
        /// <summary>
        /// Returns the remainder of <c>this</c> divided by <c>G</c> in a new GF2Polynomial
        /// </summary>
        /// 
        /// <param name="G">A GF2Polynomial != 0</param>
        /// 
        /// <returns>Returns a new GF2Polynomial (<c>this</c> % <c>G</c>)</returns>
        public GF2Polynomial Remainder(GF2Polynomial G)
        {
            // a div b = q / r
            GF2Polynomial a = new GF2Polynomial(this);
            GF2Polynomial b = new GF2Polynomial(G);
            GF2Polynomial j;
            int i;

            if (b.IsZero())
                throw new Exception();

            a.ReduceN();
            b.ReduceN();

            if (a._length < b._length)
                return a;

            i = a._length - b._length;
            while (i >= 0)
            {
                j = b.ShiftLeft(i);
                a.SubtractFromThis(j);
                a.ReduceN();
                i = a._length - b._length;
            }

            return a;
        }
        /// <summary>
        /// Divides <c>this</c> by <c>G</c> and returns the quotient and remainder in a new GF2Polynomial[2], quotient in [0], remainder in [1]
        /// </summary>
        /// 
        /// <param name="G">A GF2Polynomial != 0</param>
        /// 
        /// <returns>Returns a new GF2Polynomial[2] containing quotient and remainder</returns>
        public GF2Polynomial[] Divide(GF2Polynomial G)
        {
            // a div b = q / r
            GF2Polynomial[] result = new GF2Polynomial[2];
            GF2Polynomial q = new GF2Polynomial(_length);
            GF2Polynomial a = new GF2Polynomial(this);
            GF2Polynomial b = new GF2Polynomial(G);
            GF2Polynomial j;
            int i;

            if (b.IsZero())
                throw new Exception();

            a.ReduceN();
            b.ReduceN();

            if (a._length < b._length)
            {
                result[0] = new GF2Polynomial(0);
                result[1] = a;
                return result;
            }

            i = a._length - b._length;
            q.ExpandN(i + 1);

            while (i >= 0)
            {
                j = b.ShiftLeft(i);
                a.SubtractFromThis(j);
                a.ReduceN();
                q.XorBit(i);
                i = a._length - b._length;
            }

            result[0] = q;
            result[1] = a;

            return result;
        }