Created
July 23, 2018 13:26
-
-
Save 10long/82dec35d7fc454ce94895b0714bd90ee to your computer and use it in GitHub Desktop.
elliptic_curves_order_counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point: | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
class EC: | |
def __init__(self, a1, a2, a3,a4,a6, p): | |
self.a1 = a1 | |
self.a2 = a2 | |
self.a3 = a3 | |
self.a4 = a4 | |
self.a6 = a6 | |
self.p = p | |
self.calc_order() | |
def calc_order(self): | |
self.points = [] | |
for x in range(self.p): | |
for y in range(self.p): | |
pt = Point(x, y) | |
if self.oncurve(pt): | |
self.points.append(pt) | |
self.points_count = len(self.points) | |
self.order = len(self.points) + 1 | |
def oncurve(self, pt): | |
l = ((pt.y**2) + (self.a1 * pt.x * pt.y) + self.a3 * (pt.y)) % self.p | |
r = ((pt.x**3) + self.a2 * (pt.x**2) + self.a4 * pt.x + self.a6) % self.p | |
return l == r | |
ec = EC(0, 0, 0, 1, 1,5) | |
print("F" + str(ec.p)) | |
print( "#EC:" + str(ec.order)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment