calculate function divisor for adding 2 points

This commit is contained in:
narodnik
2022-07-20 12:18:18 +02:00
parent 10282ba4cf
commit 154fbc81da
2 changed files with 32 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ def degree(D):
def neg(D):
return tuple((-order, pnt) for order, pnt in D)
# This means D1 ~ D2 because D1 - D2 ∈ Pic(E)
D = D1 + neg(D2)
assert degree(D) == 0
assert dsum(D) == inf

View File

@@ -0,0 +1,31 @@
q = 47
Fq = GF(q)
E = EllipticCurve(Fq, (0, 5))
R.<x, y> = PolynomialRing(Fq)
def add(P, Q):
Px, Py = P[0], P[1]
Qx, Qy = Q[0], Q[1]
# We don't handle this case yet :p
assert Px != Qx
gradient = (Qy - Py) / (Qx - Px)
intersect = Py - gradient * Px
f = y - gradient * x - intersect
assert f(Px, Py) == 0
assert f(Qx, Qy) == 0
R = P + Q
Rx, Ry = R[0], R[1]
assert f(Rx, -Ry) == 0
g = x - Rx
assert g(Rx, Ry) == g(Rx, -Ry) == 0
return f / g
P = E(33, 9)
Q = E(34, 39)
# div(f) = [P] + [Q] - [P + Q] - [∞] ∈ Pic(E)
# = ([P] + [Q] - 2[∞]) - ([P + Q] - [∞])
# => [P] + [Q] - 2[∞] ~ [P + Q] - [∞]
f = add(P, Q)
print(f)