Add Elliptic Curve and docs
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from Cryptotools.Groups.curve import Curve
|
||||
|
||||
|
||||
a = 3
|
||||
b = 8
|
||||
|
||||
curve = Curve(a, b, Curve.WEIERSTRASS)
|
||||
x = curve.x
|
||||
curve.generatePoints()
|
||||
y = curve.y
|
||||
yn = curve.yn
|
||||
points = curve.getPoints()
|
||||
|
||||
P = points[10]
|
||||
Q = points[55]
|
||||
R = points[247]
|
||||
#print(f"{P.x} {P.y}")
|
||||
#print(f"{Q.x} {Q.y}")
|
||||
|
||||
# Make an addition
|
||||
Rp = curve.add(P, Q)
|
||||
#print(f"{Rp.x} {Rp.y}")
|
||||
|
||||
#print(yn)
|
||||
#print(x)
|
||||
#print(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.annotate('Q', (Q.x, Q.y + 0.5))
|
||||
|
||||
plt.plot(R.x, R.y, marker='o', color="red")
|
||||
plt.annotate('R', (R.x - 0.2, R.y + 0.5))
|
||||
|
||||
plt.plot(Rp.x, Rp.y, marker='o', color="red")
|
||||
plt.annotate('R\'', (Rp.x - 0.2, Rp.y + 0.5))
|
||||
plt.axline([P.x, P.y], [Q.x, Q.y], color="red")
|
||||
plt.axline([R.x, R.y], [Rp.x, Rp.y], linestyle="--", color="red")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user