Exemplo n.º 1
0
        private void ToIntegerPolynomial()
        {
            int[] coeffs = new int[] { 2, 0, 3, 1, 1, 5, 1, 4 };
            LongPolynomial5 p = new LongPolynomial5(new IntegerPolynomial(coeffs));

            if (!Compare.AreEqual(coeffs, p.ToIntegerPolynomial().Coeffs))
                throw new Exception("LongPolynomial5 multiply test failed!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Multiplies the polynomial with another, taking the values mod modulus and the indices mod N
        /// </summary>
        ///
        /// <param name="Factor">The polynomial factor</param>
        /// <param name="Modulus">The Modulus</param>
        ///
        /// <returns>Multiplied polynomial</returns>
        public new IntegerPolynomial Multiply(IntegerPolynomial Factor, int Modulus)
        {
            // even on 32-bit systems, LongPolynomial5 multiplies faster than IntegerPolynomial
            if (Modulus == 2048)
            {
                IntegerPolynomial poly2Pos = Factor.Clone();
                poly2Pos.ModPositive(2048);
                LongPolynomial5 poly5 = new LongPolynomial5(poly2Pos);

                return(poly5.Multiply(this).ToIntegerPolynomial());
            }
            else
            {
                return(base.Multiply(Factor, Modulus));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Multiplies the polynomial with another, taking the values mod modulus and the indices mod N
        /// </summary>
        /// 
        /// <param name="Factor">The polynomial factor</param>
        /// <param name="Modulus">The Modulus</param>
        /// 
        /// <returns>Multiplied polynomial</returns>
        public new IntegerPolynomial Multiply(IntegerPolynomial Factor, int Modulus)
        {
            // even on 32-bit systems, LongPolynomial5 multiplies faster than IntegerPolynomial
            if (Modulus == 2048)
            {
                IntegerPolynomial poly2Pos = Factor.Clone();
                poly2Pos.ModPositive(2048);
                LongPolynomial5 poly5 = new LongPolynomial5(poly2Pos);

                return poly5.Multiply(this).ToIntegerPolynomial();
            }
            else
            {
                return base.Multiply(Factor, Modulus);
            }
        }
Exemplo n.º 4
0
        private void MultTest(int[] coeffs1, int[] coeffs2)
        {
            IntegerPolynomial i1 = new IntegerPolynomial(coeffs1);
            IntegerPolynomial i2 = new IntegerPolynomial(coeffs2);
            LongPolynomial5 a = new LongPolynomial5(i1);
            DenseTernaryPolynomial b = new DenseTernaryPolynomial(i2);
            IntegerPolynomial c1 = i1.Multiply(i2, 2048);
            IntegerPolynomial c2 = a.Multiply(b).ToIntegerPolynomial();

            if (!EqualsMod(c1.Coeffs, c2.Coeffs, 2048))
                throw new Exception("LongPolynomial5 multiply test failed!");
        }