Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ warning: format of factorization is now dict like {p1: e1, p2: e2, ...}
* .find\_points\_in\_range(start, end) - list of points in range of x coordinate
* .find\_points\_rand(count) - list of count random points
* .add(p1, p2) - p1 + p2 on elliptic curve
* .power(p, n) - n✕P or (P + P + ... + P) n times
* .negate(p) - -p on elliptic curve
* .power(p, n) - n✕P or (P + P + ... + P) n times. If n < 0, firstly negate P to get (-P) and then take (-n)✕(-P)
* .generate(n) - n✕G
* .get\_order(p, limit) - slow method, trying to determine order of p; limit is max order to try

Expand Down
11 changes: 10 additions & 1 deletion libnum/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,22 @@ def add(self, p1, p2):
y = (l * (x1 - x) - y1) % self.module # yes, it's that new x
return (x, y)

def negate(self, p):
"""
Negation of a point or a new point Q = -P where P + Q = O
"""
return (p[0], -p[1] % self.module)

def power(self, p, n):
"""
n✕P or (P + P + ... + P) n times
If n < 0, firstly negate P to get -P and then take (-n)✕(-P)
"""
if n < 0:
return self.power(self.negate(p), -n)
if n == 0 or self.is_null(p):
return NULL_POINT

res = NULL_POINT
while n:
if n & 1:
Expand Down