Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/shamir_secret_sharing/deterministic_coefficients.py
2589 views
1
def attack(p, k, a1, f, x, y):
2
"""
3
Recovers the shared secret if the coefficients are generated deterministically, and a single share is given.
4
:param p: the prime used for Shamir's secret sharing
5
:param k: the amount of shares needed to unlock the secret
6
:param a1: the first coefficient of the polynomial
7
:param f: a function which takes a coefficient and returns the next coefficient in the polynomial
8
:param x: the x coordinate of the given share
9
:param y: the y coordinate of the given share
10
:return: the shared secret
11
"""
12
s = y
13
a = a1
14
for i in range(1, k):
15
s -= a * x ** i
16
a = f(a)
17
18
return s % p
19
20