예제 #1
0
        public void DivideTest()
        {
            ParameterSet parameters = ECParameterSets.ParamSet_EC_P256_V1;

            for (int i = 0; i < 10; ++i)
            {
                FieldZqElement a = parameters.Group.FieldZq.GetRandomElement(false);
                FieldZqElement b = parameters.Group.FieldZq.GetRandomElement(true);
                FieldZqElement c = a.Divide(b);
                Assert.AreEqual <FieldZqElement>(a * b.Invert(), c, "a.divide(b).");
                FieldZqElement d = a / b;
                Assert.AreEqual <FieldZqElement>(c, d, "a / b");
            }

            FieldZq Zq = FieldZq.CreateFieldZq(new byte[] { 0x05 });

            Assert.AreEqual <FieldZqElement>(Zq.GetElement(4), Zq.GetElement(2) / Zq.GetElement(3), "2/3 = 4");
            Assert.AreEqual <FieldZqElement>(Zq.GetElement(4), Zq.GetElement(1) / Zq.GetElement(4), "1/4 = 4");
            Assert.AreEqual <FieldZqElement>(Zq.GetElement(1), Zq.GetElement(2) / Zq.GetElement(2), "2/3 = 1");
        }