Esempio n. 1
0
    def test_ne(self):
        a = FieldElement(11, 71)
        b = FieldElement(11, 71)
        c = FieldElement(7, 71)

        self.assertTrue(a != c)
        self.assertFalse(a != b)
Esempio n. 2
0
    def test_eq(self):
        a = FieldElement(11, 71)
        b = FieldElement(11, 71)
        c = FieldElement(7, 71)

        self.assertTrue(a == b)
        self.assertFalse(a == c)
Esempio n. 3
0
 def test_pow(self):
     a = FieldElement(5, 17)
     b = FieldElement(8, 17)
     self.assertTrue(a ** 2 == b)
     a = FieldElement(7, 13)
     b = FieldElement(8, 13)
     self.assertTrue(a ** -3 == b)
Esempio n. 4
0
 def test_sub(self):
     a = FieldElement(13, 17)
     b = FieldElement(15, 17)
     c = FieldElement(15, 17)
     self.assertTrue(a - b == c)
     a = FieldElement(13, 17)
     b = FieldElement(1, 17)
     c = FieldElement(12, 17)
     self.assertTrue(a - b == c)
Esempio n. 5
0
 def test_field_elements_on_curve(self):
     prime = 223
     a = FieldElement(0, prime)
     b = FieldElement(7, prime)
     valid_points = ((192, 105), (17, 56), (1, 193))
     invalid_points = ((200, 119), (42, 99))
     for x_raw, y_raw in valid_points:
         x = FieldElement(x_raw, prime)
         y = FieldElement(y_raw, prime)
         Point(x, y, a, b)
     for x_raw, y_raw in invalid_points:
         x = FieldElement(x_raw, prime)
         y = FieldElement(y_raw, prime)
         with self.assertRaises(ValueError):
             Point(x, y, a, b)
Esempio n. 6
0
 def test_truediv(self):
     a = FieldElement(5, 17)
     b = FieldElement(8, 17)
     c = FieldElement(7, 17)
     self.assertTrue(a / b == c)
Esempio n. 7
0
 def test_mul(self):
     a = FieldElement(13, 17)
     b = FieldElement(3, 17)
     c = FieldElement(5, 17)
     self.assertTrue(a * b == c)
Esempio n. 8
0
    def test_add(self):
        a = FieldElement(14, 17)
        b = FieldElement(7, 17)
        c = FieldElement(4, 17)

        self.assertTrue(a + b == c)
Esempio n. 9
0
 def test_add_for_field_points(self):
     prime = 223
     a = FieldElement(0, prime)
     b = FieldElement(7, prime)
     p1 = Point(FieldElement(170, prime), FieldElement(142, prime), a, b)
     p2 = Point(FieldElement(60, prime), FieldElement(139, prime), a, b)
     p_result = Point(FieldElement(220, prime), FieldElement(181, prime), a,
                      b)
     self.assertTrue(p1 + p2 == p_result)
     p1 = Point(FieldElement(47, prime), FieldElement(71, prime), a, b)
     p2 = Point(FieldElement(17, prime), FieldElement(56, prime), a, b)
     p_result = Point(FieldElement(215, prime), FieldElement(68, prime), a,
                      b)
     self.assertTrue(p1 + p2 == p_result)
     p1 = Point(FieldElement(143, prime), FieldElement(98, prime), a, b)
     p2 = Point(FieldElement(76, prime), FieldElement(66, prime), a, b)
     p_result = Point(FieldElement(47, prime), FieldElement(71, prime), a,
                      b)
     self.assertTrue(p1 + p2 == p_result)