コード例 #1
0
    def test_summ(self):
        ec = EllipticCurve("test")
        point_a = Point(17, 10)
        point_b = Point(95, 31)
        ref = Point(1, 54)
        result = ec.summ(point_a, point_b)
        self.assertTrue(result == ref)

        point_a = Point(80, 10)
        point_b = Point(80, 87)
        ref = Point(0, 1, 0)
        self.assertEqual(ec.summ(point_a, point_b), ref)

        ec = EllipticCurve('A')
        a = ec.get_forming()
        self.assertEqual(ec.summ(a, ec.get_zero()), a)
コード例 #2
0
    def test_multiply_by_number(self):
        ec = EllipticCurve('A')
        a = ec.get_forming()
        for k in [-1233535, 1231, 0, -1, 1, 1231341]:
            self.assertTrue(ec.is_on_curve(ec.multiply_by_number(a, k)))
        mul = ec.multiply_by_number
        self.assertEqual(mul(mul(a, 10), 10), mul(a, 100))
        self.assertEqual(mul(mul(a, 2), -3), mul(a, -6))
        self.assertEqual(mul(mul(a, -4), 7), mul(a, -28))
        self.assertEqual(ec.summ(mul(a, 123), mul(a, -122)), mul(a, 1))

        ec = EllipticCurve('test')
        point = Point(3, 6)
        n_s = range(7)
        rights = [
            Point(0, 1, 0),
            Point(3, 6),
            Point(80, 10),
            Point(80, 87),
            Point(3, 91),
            Point(0, 1, 0),
            Point(3, 6)
        ]
        for n, right in zip(n_s, rights):
            print(right)
            print(ec.multiply_by_number(point, n))
            self.assertEqual(ec.multiply_by_number(point, n), right)