Esempio n. 1
0
        public void testMult()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            IntegerPolynomial i2 = new IntegerPolynomial(new int[] { 1729, 1924, 806, 179, 1530, 1381, 1695, 60 });
            LongPolynomial2   a  = new LongPolynomial2(i1);
            LongPolynomial2   b  = new LongPolynomial2(i2);
            IntegerPolynomial c1 = i1.Multiply(i2, 2048);
            IntegerPolynomial c2 = a.Multiply(b).ToIntegerPolynomial();

            Assert.True(c1.coeffs.SequenceEqual(c2.coeffs));

            SecureRandom rng = new SecureRandom();

            for (int i = 0; i < 10; i++)
            {
                int N = 2 + rng.NextInt(2000);
                i1 = PolynomialGenerator.GenerateRandom(N, 2048);
                i2 = PolynomialGenerator.GenerateRandom(N, 2048);
                a  = new LongPolynomial2(i1);
                b  = new LongPolynomial2(i2);
                c1 = i1.Multiply(i2);
                c1.ModPositive(2048);
                c2 = a.Multiply(b).ToIntegerPolynomial();
                Assert.True(c1.coeffs.SequenceEqual(c2.coeffs));
            }
        }
Esempio n. 2
0
        private void MultTest()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            IntegerPolynomial i2 = new IntegerPolynomial(new int[] { 1729, 1924, 806, 179, 1530, 1381, 1695, 60 });
            LongPolynomial2   a  = new LongPolynomial2(i1);
            LongPolynomial2   b  = new LongPolynomial2(i2);
            IntegerPolynomial c1 = i1.Multiply(i2, 2048);
            IntegerPolynomial c2 = a.Multiply(b).ToIntegerPolynomial();

            if (!Compare.AreEqual(c1.Coeffs, c2.Coeffs))
            {
                throw new Exception("LongPolynomial2 multiply test failed!");
            }

            // test 10 random polynomials
            Random rng = new Random();

            for (int i = 0; i < 10; i++)
            {
                int N = 2 + rng.Next(2000);
                i1 = (IntegerPolynomial)PolynomialGeneratorForTesting.GenerateRandom(N, 2048);
                i2 = (IntegerPolynomial)PolynomialGeneratorForTesting.GenerateRandom(N, 2048);
                a  = new LongPolynomial2(i1);
                b  = new LongPolynomial2(i2);
                c1 = i1.Multiply(i2);
                c1.ModPositive(2048);
                c2 = a.Multiply(b).ToIntegerPolynomial();

                if (!Compare.AreEqual(c1.Coeffs, c2.Coeffs))
                {
                    throw new Exception("LongPolynomial2 multiply test failed!");
                }
            }
        }
Esempio n. 3
0
        public void testMult2And()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            LongPolynomial2   i2 = new LongPolynomial2(i1);

            i2.mult2And(2047);
            i1.Multiply(2);
            i1.ModPositive(2048);
            Assert.True(i1.coeffs.SequenceEqual(i2.ToIntegerPolynomial().coeffs));
        }
Esempio n. 4
0
        public void testSubAnd()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            IntegerPolynomial i2 = new IntegerPolynomial(new int[] { 1729, 1924, 806, 179, 1530, 1381, 1695, 60 });
            LongPolynomial2   a  = new LongPolynomial2(i1);
            LongPolynomial2   b  = new LongPolynomial2(i2);

            a.SubAnd(b, 2047);
            i1.Sub(i2);
            i1.ModPositive(2048);
            Assert.True(a.ToIntegerPolynomial().coeffs.SequenceEqual(i1.coeffs));
        }
Esempio n. 5
0
        private void Mult2AndTest()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            LongPolynomial2   i2 = new LongPolynomial2(i1);

            i2.Mult2And(2047);
            i1.Multiply(2);
            i1.ModPositive(2048);

            if (!Compare.AreEqual(i1.Coeffs, i2.ToIntegerPolynomial().Coeffs))
            {
                throw new Exception("LongPolynomial2 Mult2And test failed!");
            }
        }
Esempio n. 6
0
        private void SubAndTest()
        {
            IntegerPolynomial i1 = new IntegerPolynomial(new int[] { 1368, 2047, 672, 871, 1662, 1352, 1099, 1608 });
            IntegerPolynomial i2 = new IntegerPolynomial(new int[] { 1729, 1924, 806, 179, 1530, 1381, 1695, 60 });
            LongPolynomial2   a  = new LongPolynomial2(i1);
            LongPolynomial2   b  = new LongPolynomial2(i2);

            a.SubAnd(b, 2047);
            i1.Subtract(i2);
            i1.ModPositive(2048);

            if (!Compare.AreEqual(a.ToIntegerPolynomial().Coeffs, i1.Coeffs))
            {
                throw new Exception("LongPolynomial2 SubAnd test failed!");
            }
        }