Skip to content

Commit

Permalink
Update primecurve.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tatianab committed Oct 17, 2014
1 parent dd59fe2 commit ef3cee9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions primecurves/primecurves/primecurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
## /author Tatiana Bradley
## /brief Implementation of the PrimeCurve class.

from primepoint import *
from primefieldelement import *

class PrimeCurve:

"""
Expand All @@ -25,6 +28,8 @@ def __init__(self, a, b, prime):
self.a = a;
self.b = b;
self.prime = prime;
self.allPoints = [PrimePoint.inf()];
self.order = None

@classmethod
def default(cls):
Expand All @@ -34,3 +39,37 @@ def default(cls):

def __repr__(self):
return "y^2 = x^3 + " + str(self.a) + "x + " + str(self.b) + " over F_" + str( self.prime )


# OTHER FUNCTIONS
def onCurve(self, x, y):
x = PrimeFieldElement(x, self.prime)
y = PrimeFieldElement(y, self.prime)
lhs = y ** 2
rhs = x ** 3 + x * self.a + self.b
return (lhs == rhs)

# GET A "RANDOM" POINT (prelim)
def getPoint(self):
found = False
while (not found):
x = PrimeFieldElement.random(self.prime).value
for y in range(self.prime):
if (self.onCurve(x, y)):
return PrimePoint(x, y, self)

# GET ALL THE POINTS!
def getAllPoints(self):
for x in range(self.prime):
for y in range(self.prime):
if (self.onCurve(x, y)):
self.allPoints += [ PrimePoint(x, y, self) ]

def getOrder(self):
if self.order is None:
if len(self.allPoints) > 1:
self.order = len(self.allPoints)
else:
return "NO INFO"
# ^ NEEDS TO BE MODIFIED
return self.order

0 comments on commit ef3cee9

Please sign in to comment.