diff options
author | Determinant <[email protected]> | 2024-08-22 22:54:28 -0700 |
---|---|---|
committer | Determinant <[email protected]> | 2024-08-22 22:54:28 -0700 |
commit | 000c6c7d91a52fb0862d0d20782513d23b8865ae (patch) | |
tree | 9e324170b1a6d2f21bd64b9f7cf89f002057ad0c | |
parent | 5737a0064ca7862fed5c2244b906d8829b6badc4 (diff) |
...
-rw-r--r-- | shamir.py | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -51,10 +51,10 @@ def _lagrange_interpolate(x, x_s, y_s, p): assert k == len(set(x_s)), "points must be distinct" def prod(vals): # product of inputs - accum = 1 + r = 1 for v in vals: - accum *= v - return accum + r = (r * v) % p + return r nums = [] # avoid inexact division dens = [] for i in range(k): @@ -65,7 +65,7 @@ def _lagrange_interpolate(x, x_s, y_s, p): nums.append(prod(x - o for o in others)) # \Prod_{j \neq i}{(x - x_j)} dens.append(prod(cur - o for o in others)) # \Prod_{j \neq i}{(x_i - x_j)} den = prod(dens) - num = sum([_divmod(nums[i] * den * y_s[i] % p, dens[i], p) + num = sum([_divmod((nums[i] * den * y_s[i]) % p, dens[i], p) for i in range(k)]) return (_divmod(num, den, p) + p) % p |