Ejemplo n.º 1
0
        public void GenerateCurveAndPointCheck()
        {
            ElipticCurve curve = new ElipticCurve(64);

            curve.GenerateRandomCurve();

            Point p1 = curve.GenerateRandomPointOnCurve();

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(p1));

            Point p2 = curve.GenerateRandomPointOnCurve();

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(p1));

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(p1 + p1));

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(p1 + p2));
        }
Ejemplo n.º 2
0
        public void ScalarMultiplicationTests()
        {
            ElipticCurve curve = new ElipticCurve(64);

            curve.GenerateRandomCurve();
            Point randomPoint = curve.GenerateRandomPointOnCurve();

            Point testPoint = curve.ScalarMultiplication(randomPoint, 1);

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(testPoint));

            testPoint = curve.ScalarMultiplication(randomPoint, 5);
            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(testPoint));

            testPoint = curve.ScalarMultiplication(randomPoint, 100);
            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(testPoint));

            testPoint = curve.ScalarMultiplication(randomPoint, BigInteger.Parse("999999999999999999999999999999999999999999999999999999999999"));

            Assert.IsTrue(curve.CheckIfPointBelongsToCurve(testPoint));
        }
Ejemplo n.º 3
0
        public void CheckIfStaticPointsBelongsToCurve()
        {
            BigInteger   a     = 6;
            BigInteger   p     = 11;
            ElipticCurve curve = new ElipticCurve(a, 4, p);
            Point        p1    = new Point(7, 9, a, p);
            Point        p2    = new Point(3, 4, a, p);

            bool result = curve.CheckIfPointBelongsToCurve(p1);

            Assert.IsTrue(result);

            result = curve.CheckIfPointBelongsToCurve(p2);
            Assert.IsTrue(result);

            result = curve.CheckIfPointBelongsToCurve(p1 + p1);
            Assert.IsTrue(result);

            result = curve.CheckIfPointBelongsToCurve(p1 + p2);
            Assert.IsTrue(result);

            result = curve.CheckIfPointBelongsToCurve(Point.NeutralElement(a, p));
            Assert.IsTrue(result);
        }