Ejemplo n.º 1
0
        /// <summary>
        /// Compute <c>this</c> element to the power of 2
        /// </summary>
        ///
        /// <returns>Returns <c>this</c>^2</returns>
        public override GF2nElement Square()
        {
            GF2nONBElement result = new GF2nONBElement(this);

            result.SquareThis();

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Multiplicatively invert of this element (overwrite <c>this</c>)
        /// </summary>
        public void InvertThis()
        {
            if (IsZero())
            {
                throw new ArithmeticException();
            }

            int r = 31; // mDegree kann nur 31 Bits lang sein!!!

            // Bitlaenge von mDegree:
            for (bool found = false; !found && r >= 0; r--)
            {
                if (((mDegree - 1) & _mBitmask[r]) != 0)
                {
                    found = true;
                }
            }
            r++;

            GF2nElement m = Zero((GF2nONBField)mField);
            GF2nElement n = new GF2nONBElement(this);
            int         k = 1;

            for (int i = r - 1; i >= 0; i--)
            {
                m = (GF2nElement)n.Clone();
                for (int j = 1; j <= k; j++)
                {
                    m.SquareThis();
                }

                n.MultiplyThisBy(m);

                k <<= 1;
                if (((mDegree - 1) & _mBitmask[i]) != 0)
                {
                    n.SquareThis();
                    n.MultiplyThisBy(this);
                    k++;
                }
            }
            n.SquareThis();
        }