Add Elliptic Curve and docs
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from Cryptotools.Groups.point import Point
|
||||
from Cryptotools.Groups.curve import Curve
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from math import sqrt
|
||||
|
||||
|
||||
a = 3
|
||||
b = 8
|
||||
|
||||
curve = Curve(a, b, Curve.WEIERSTRASS)
|
||||
x = curve.x
|
||||
curve.generatePoints()
|
||||
y = curve.y
|
||||
yn = curve.yn
|
||||
points = curve.getPoints()
|
||||
pointsReverse = curve.getPointsSym()
|
||||
|
||||
P = points[10]
|
||||
Q = curve.find_reverse(P)
|
||||
|
||||
# We made the addition
|
||||
# The result is the point at infinity
|
||||
R = curve.add(P, Q)
|
||||
print(f"{R.x} {R.y}")
|
||||
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(x, y, color='b', label=f'$y^2 = x^3 + {a}x + {b}$')
|
||||
plt.plot(x, yn, color='b', )
|
||||
plt.plot(P.x, P.y, marker='o', color="red")
|
||||
plt.annotate('P', (P.x, P.y + 0.5))
|
||||
|
||||
plt.plot(Q.x, Q.y, marker='o', color="red")
|
||||
plt.text(-1 , 11, f"R = infinity")
|
||||
plt.annotate('Q', (Q.x, Q.y + 0.5))
|
||||
|
||||
|
||||
plt.axline([P.x, P.y], [Q.x, Q.y], color="red")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user