Ejemplo n.º 1
0
        public void TestBinaryDecimalCast()
        {
            SLongIntB A = new SLongIntB("-20976982698769825692774362798672976276668754000000000000000765700000000");
            SLongIntD B = (SLongIntD)A;

            Assert.AreEqual(A.ToString(), B.ToString());
            Assert.AreEqual((SLongIntD)A, B);
            Assert.AreEqual(A, (SLongIntB)B);
        }
Ejemplo n.º 2
0
        public void TestSubstraction1()
        {
            SLongIntB N = new SLongIntB("2945729752935981200000005151659293467923476293623");
            RandomLong rand = new RandomLong((ulong)DateTime.Now.Millisecond);

            for (int i = 0; i < 1000; ++i)
            {
                SLongIntB A = new SLongIntB(rand.Next(N), ConstructorMode.Assign);
                SLongIntB B = new SLongIntB(rand.Next(N), ConstructorMode.Assign);

                SLongIntB C = A + B;

                Assert.AreEqual(C - B, A, C.ToString() + " " + B.ToString());
                Assert.AreEqual(C - A, B, C.ToString() + " " + A.ToString());

                Assert.AreEqual(C - 0, C);
                Assert.AreEqual(C - C, (SLongIntB)0);
            }
        }
Ejemplo n.º 3
0
        //[Test()]
        public void TestExtendedGCD()
        {
            SLongIntB N = new SLongIntB("2945729752935981200000005151659293467923476293623");
            RandomLong rand = new RandomLong((ulong)DateTime.Now.Millisecond);

            SLongIntB U = null, V = null;

            for (int i = 0; i < 1000; ++i)
            {
                SLongIntB temp1 = new SLongIntB(rand.Next(N), ConstructorMode.Assign);
                SLongIntB temp2 = new SLongIntB(rand.Next(N), ConstructorMode.Assign);

                SLongIntB gcd = CryptoMath.eXtendedGCD(temp1, temp2, out U, out V);
                SLongIntB gcdB = CryptoMath.GCD(temp1, temp2);

                Assert.AreEqual(gcd, temp1*U + temp2*V);
                Assert.AreEqual(gcd, gcdB, temp1.ToString() + " " + temp2.ToString() + " " + gcd.ToString() + " " + gcdB.ToString());
            }
        }
Ejemplo n.º 4
0
        public void TestPower()
        {
            SLongIntB N = new SLongIntB("2945");
            RandomLong rand = new RandomLong((ulong)DateTime.Now.Millisecond);
            Random rand32 = new Random(DateTime.Now.Millisecond);

            SLongIntB m = new SLongIntB("98696766574783");

            for (int i = 0; i < 100; ++i)
            {
                SLongIntB temp = new SLongIntB(rand.Next(N), ConstructorMode.Assign);
                int power = rand32.Next(ushort.MaxValue) % 10000;

                Assert.AreEqual(CryptoMath.ExpMod5((ULongIntB)temp, (ULongIntB)power, (ULongIntB)m), LongMath.Exp((ULongIntB)temp, (ulong)power) % (ULongIntB)m,
                                temp.ToString() + "^" + power.ToString());
            }
        }
Ejemplo n.º 5
0
        public void TestDivision2()
        {
            SLongIntB N = new SLongIntB("2945729752935981200000005151659293467923476293623");
            RandomLong rand = new RandomLong((ulong)DateTime.Now.Millisecond);

            for (int i = 0; i < 1000; ++i)
            {
                SLongIntB A = new SLongIntB(rand.Next(N), ConstructorMode.Assign);
                SLongIntB B = new SLongIntB(rand.Next(N), ConstructorMode.Assign);

                if (B == 0)
                    continue;

                if ((B * (A / B)) + (A % B) != A)
                {
                    Console.WriteLine(A);
                    Console.WriteLine(B);

                    Console.WriteLine((A/B).ToString());
                    Console.WriteLine((A%B).ToString());
                }

                Assert.AreEqual((B * (A / B)) + (A % B), A, string.Join(" ",
                        new string[]{ A.ToString(), B.ToString(), (A/B).ToString(), (A%B).ToString() }));
            }
        }