Exemplo n.º 1
0
    def get_polynomials(self):
        polynomials = [
            # 9x⁹ + 28x⁸ + 901x⁷ + 321x⁶ + 982x⁵ + 123x⁴ + 932x³ + 2318x² + 780x + 11235
            [11235, 780, 2318, 932, 123, 982, 321, 901, 28, 9],
            # 395x⁹ +  9777x⁸ + 10945x⁷ + 6364x⁶ + 3071x⁵ + 611x⁴ + 3960x³ + 2525x² + 7609x + 11277
            [11277, 7609, 2525, 3960, 611, 3071, 6364, 10945, 9777, 395],
            # 1617x⁹ + 5033x⁸ + 1743x⁷ + 10565x⁶ + 4879x⁵ + 6705x⁴ + 9970x³ + 4195x² + 3213x + 7602
            [7602, 3213, 4195, 9970, 6705, 4879, 10565, 1743, 5033, 1617],
            # 3171x⁹ + 8005x⁸ + 5082x⁷ + 6906x⁶ + 8676x⁵ + 7927x⁴ + 1603x³ + 7589x² + 4566x + 495
            [495, 4566, 7589, 1603, 7927, 8676, 6906, 5082, 8005, 3171],
            # 426x⁹ + 6260x⁸ + 8483x⁷ + 8896x⁶ + 6219x⁵ + 10107x⁴ + 3059x³ + 1822x² + 91x + 11874
            [11874, 91, 1822, 3059, 10107, 6219, 8896, 8483, 6260, 426]
        ]

        return list(map(lambda p: Polynomial(p), polynomials))
Exemplo n.º 2
0
 def share(self, secret, threshold, points):
     coef = [secret]
     coef += [self.random.randitem() for j in range(threshold-1)]
     p = Polynomial(list(reversed(coef)))
     shares = [(pt, p.evaluate(pt)) for pt in points]
     return shares
Exemplo n.º 3
0
 def test_lagrange(self):
     points, results = self.get_points()
     for i in range(len(points)):
         k = Polynomial.lagrange(points[i], 0, MODSZ)
         assert (results[i] == k)
Exemplo n.º 4
0
 def test_Polynomial_from_factored_form(self):
     p = Polynomial.from_roots([4, 7, 9])
     self.assertEquals(p, Polynomial([1, -20, 127, -252]))
Exemplo n.º 5
0
 def test_Polynomial_evaluate_ValueIsCorrect(self):
     p = Polynomial([3, 5, 78, 2])
     
     value = p.evaluate(3)
     
     self.assertEquals(value, 362)