Пример #1
0
        /// <summary>
        /// Reduces this GF2nPolynomialElement modulo the field-polynomial
        /// </summary>
        private void ReduceThis()
        {
            if (polynomial.Length > mDegree)
            {     // really reduce ?
                if (((GF2nPolynomialField)mField).IsTrinomial)
                { // fieldpolonomial
                    // is trinomial
                    int tc;
                    try
                    {
                        tc = ((GF2nPolynomialField)mField).Tc;
                    }
                    catch (Exception NATExc)
                    {
                        throw new Exception("GF2nPolynomialElement.Reduce: the field polynomial is not a trinomial!");
                    }
                    // do we have to use slow bitwise reduction ?
                    if (((mDegree - tc) <= 32) || (polynomial.Length > (mDegree << 1)))
                    {
                        ReduceTrinomialBitwise(tc);
                        return;
                    }
                    polynomial.ReduceTrinomial(mDegree, tc);

                    return;
                }
                else if (((GF2nPolynomialField)mField).IsPentanomial) // fieldpolynomial is pentanomial
                {
                    int[] pc;
                    try
                    {
                        pc = ((GF2nPolynomialField)mField).Pc;
                    }
                    catch (Exception NATExc)
                    {
                        throw new Exception("GF2nPolynomialElement.Reduce: the field polynomial is not a pentanomial!");
                    }
                    // do we have to use slow bitwise reduction ?
                    if (((mDegree - pc[2]) <= 32) || (polynomial.Length > (mDegree << 1)))
                    {
                        ReducePentanomialBitwise(pc);
                        return;
                    }
                    polynomial.ReducePentanomial(mDegree, pc);

                    return;
                }
                else
                { // fieldpolynomial is something else
                    polynomial = polynomial.Remainder(mField.FieldPolynomial);
                    polynomial.ExpandN(mDegree);

                    return;
                }
            }

            if (polynomial.Length < mDegree)
            {
                polynomial.ExpandN(mDegree);
            }
        }