Пример #1
0
        /// <summary>
        /// Compute the product of this element and <c>factor</c>
        /// </summary>
        ///
        /// <param name="Factor">he factor</param>
        ///
        /// <returns>Returns <c>this * factor</c> </returns>
        public override IGFElement Multiply(IGFElement Factor)
        {
            GF2nONBElement result = new GF2nONBElement(this);

            result.MultiplyThisBy(Factor);
            return(result);
        }
Пример #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();
        }