Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/ecc/parameter_recovery.py
2589 views
1
def attack(p, x1, y1, x2, y2):
2
"""
3
Recovers the a and b parameters from an elliptic curve when two points are known.
4
:param p: the prime of the curve base ring
5
:param x1: the x coordinate of the first point
6
:param y1: the y coordinate of the first point
7
:param x2: the x coordinate of the second point
8
:param y2: the y coordinate of the second point
9
:return: a tuple containing the a and b parameters of the elliptic curve
10
"""
11
a = pow(x1 - x2, -1, p) * (pow(y1, 2, p) - pow(y2, 2, p) - (pow(x1, 3, p) - pow(x2, 3, p))) % p
12
b = (pow(y1, 2, p) - pow(x1, 3, p) - a * x1) % p
13
return int(a), int(b)
14
15