示例#1
0
        /// <summary>
        /// Взятие целой части от деления многочлена на divider
        /// </summary>
        /// <param name="number"> Число </param>
        /// <param name="divider"> Делитель полинома </param>
        /// <returns> Целая часть многочлена </returns>
        public static uint Dividing(uint number, uint divider)
        {
            int numberLength  = WorkWithBits.FindBinaryLength(number);
            int dividerLength = WorkWithBits.FindBinaryLength(divider);

            if (dividerLength > numberLength) // если число в модуле больше, то уравнение и есть остаток
            {
                return(number);
            }

            uint activeDegree;
            uint answer = 0;

            // цикл самого деления
            while (true)
            {
                activeDegree = (uint)1 << (numberLength - dividerLength);

                number       = number ^ Multy(activeDegree, divider);
                numberLength = WorkWithBits.FindBinaryLength(number);

                answer = answer ^ activeDegree;

                if (number == 0)
                {
                    return(answer);
                }

                if (dividerLength > numberLength) // есть остаток
                {
                    return(answer);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Взятие остатка от деления на mod
        /// </summary>
        /// <param name="number"> Число </param>
        /// <param name="mod"> Модуль полинома </param>
        /// <returns> Остаток многочлена </returns>
        public static uint Mod(uint number, uint mod)
        {
            int numberLength = WorkWithBits.FindBinaryLength(number);
            int modLength    = WorkWithBits.FindBinaryLength(mod);

            if (modLength > numberLength) // если число в модуле больше, то уравнение и есть остаток
            {
                return(number);
            }

            uint activeDegree;

            // цикл самого деления
            while (true)
            {
                activeDegree = (uint)1 << (numberLength - modLength);

                number       = number ^ Multy(activeDegree, mod);
                numberLength = WorkWithBits.FindBinaryLength(number);

                if (number == 0)
                {
                    return(number);
                }

                if (modLength > numberLength) // есть остаток
                {
                    return(number);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Умножение полиномов
        /// </summary>
        /// <param name="firstNumber"> Первый полином </param>
        /// <param name="secondNumber"> Второй полином </param>
        /// <returns> Возвращает умножение двух полиномов </returns>
        public static uint Multy(uint firstNumber, uint secondNumber)
        {
            int numberBinaryLengthFirstElement  = WorkWithBits.FindBinaryLength(firstNumber);
            int numberBinaryLengthSecondElement = WorkWithBits.FindBinaryLength(secondNumber);

            uint answer = 0;
            uint tmpConjunction;
            uint tmpXor;

            for (int i = 0; i < numberBinaryLengthFirstElement; i++)
            {
                for (int j = 0; j < numberBinaryLengthSecondElement; j++)
                {
                    tmpConjunction = (uint)(WorkWithBits.PrintBit(firstNumber, i) & WorkWithBits.PrintBit(secondNumber, j));
                    tmpXor         = (uint)WorkWithBits.PrintBit(answer, i + j) ^ tmpConjunction;
                    answer         = (uint)WorkWithBits.SetOrRemove(answer, tmpXor, i + j);
                }
            }
            return(answer);
        }
示例#4
0
        /// <summary>
        /// Выводит полином в подобающем пользовательском виде
        /// (степень x это нумерация бита справа налево)
        /// </summary>
        /// <param name="number"> Полином </param>
        /// <returns> Возвращает строку в виде привычного полинома </returns>
        public static string PrintGfElement(uint number)
        {
            int           numberBinaryLength = WorkWithBits.FindBinaryLength(number);
            StringBuilder answer             = new StringBuilder();

            for (int i = numberBinaryLength; i >= 0; i--)
            {
                if (WorkWithBits.PrintBit(number, i) == 1)
                {
                    if (i == 0)
                    {
                        answer.Append(1).Append(" + ");
                        break;
                    }
                    answer.Append("x^").Append(i).Append(" + ");
                }
            }
            answer.Remove(answer.Length - 3, 3);

            return(answer.ToString());
        }