def test_on_curve(self):
        prime = 223
        field = generate_finite_field(prime)

        a = field(0)
        b = field(7)

        valid_points = [
            (192, 105),
            (17, 56),
            (1, 193),
        ]
        invalid_points = [(200, 119), (42, 99)]

        # valid test
        for x_raw, y_raw in valid_points:
            x = field(x_raw)
            y = field(y_raw)
            Point(x, y, a, b)

        # invalid test
        for x_raw, y_raw in invalid_points:
            x = field(x_raw)
            y = field(y_raw)
            with self.assertRaises(ValueError):
                Point(x, y, a, b)
def exercise2():
    finite223 = generate_finite_field(223)
    point_list = [(170, 142), (60, 139), (47, 71), (17, 56), (143, 98),
                  (76, 66)]

    points = [(finite223(point[0]), finite223(point[1]))
              for point in point_list]

    a = finite223(0)
    b = finite223(7)

    for i in range(3):
        point1 = Point(*points[2 * i], a, b)
        point2 = Point(*points[2 * i + 1], a, b)
        print("{} + {} = ".format(point_list[2 * i], point_list[2 * i + 1]))
        print(point1 + point2)
    def test_add(self):
        finite223 = generate_finite_field(223)
        point_list = [(170, 142), (60, 139), (47, 71), (17, 56), (143, 98),
                      (76, 66)]

        points = [(finite223(point[0]), finite223(point[1]))
                  for point in point_list]

        a = finite223(0)
        b = finite223(7)

        answer_list_raw = [(220, 181), (215, 68), (47, 71)]
        answer_elements = [(finite223(point[0]), finite223(point[1]))
                           for point in answer_list_raw]
        answer_list = [Point(*point, a, b) for point in answer_elements]

        for i in range(3):
            point1 = Point(*points[2 * i], a, b)
            point2 = Point(*points[2 * i + 1], a, b)
            self.assertEqual(point1 + point2, answer_list[i])
def example1():
    field = generate_finite_field(223)
    a = field(0)
    b = field(7)
    x = field(47)
    y = field(71)
    p = Point(x, y, a, b)

    for s in range(1, 21):
        result = s * p
        print("{}*(47, 71) = ({}, {})".format(s, result.x.num, result.y.num))
def exercise1():
    finite223 = generate_finite_field(223)
    point_list = [(192, 105), (17, 56), (200, 119), (1, 193), (42, 99)]

    point_field_list = [(finite223(point[0]), finite223(point[1]))
                        for point in point_list]

    a = finite223(0)
    b = finite223(7)

    for point in point_field_list:
        try:
            print(Point(*point, a, b))
        except ValueError as e:
            print(e)
def exercise5():
    field = generate_finite_field(223)
    a = field(0)
    b = field(7)
    x = field(15)
    y = field(86)
    p = Point(x, y, a, b)
    gen_p = p

    print("{} generates...".format(p))
    while True:
        print(gen_p)
        gen_p += p

        if gen_p == p:
            break
def exercise4():
    finite223 = generate_finite_field(223)
    point_list_raw = [(192, 105), (143, 98), (47, 71), (47, 71), (47, 71),
                      (47, 71)]

    scalar_list = [2, 2, 2, 4, 8, 21]

    points = [(finite223(point[0]), finite223(point[1]))
              for point in point_list_raw]

    a = finite223(0)
    b = finite223(7)

    for i in range(len(points)):
        print("{}*{} = ".format(scalar_list[i], point_list_raw[i]))
        point = Point(*points[i], a, b)
        print(scalar_list[i] * point)
Example #8
0
def example1():
    # 타원 곡선 정보
    a = 0
    b = 7

    # 유한체 정보
    p = 2**256 - 2**32 - 977

    # 유한군 정보
    gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
    gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
    n = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141

    print("Validate generator point(i.e point is on the curve : {}".format(
        gy**2 % p == (gx**3 + a * gx + b) % p))

    field = generate_finite_field(p)
    x = field(gx)
    y = field(gy)
    a = field(a)
    b = field(b)
    generotor = Point(x, y, a, b)
    print("Validate the order of group(i.e n*g == 0) : {}".format(n *
                                                                  generotor))