Add Elliptic Curve and docs
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#!/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()
|
||||
|
||||
#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.legend()
|
||||
plt.show()
|
||||
@@ -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()
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from Cryptotools.Groups.curve import Curve
|
||||
from Cryptotools.Groups.point import Point
|
||||
|
||||
|
||||
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]
|
||||
nP = curve.scalar(P, 5)
|
||||
print(f"{nP.x} {nP.y}")
|
||||
|
||||
# For testing, we may add n times with the addition operation for the Scalar Multiplication
|
||||
tmp = Point(0, 0)
|
||||
for i in range(5):
|
||||
tmp = curve.add(P, tmp)
|
||||
|
||||
# Unfortunately, the result is approximatively the same
|
||||
# the multiplication need to be more accurate
|
||||
# if tmp == nP:
|
||||
# print(True)
|
||||
|
||||
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(nP.x, nP.y, marker='o', color="red")
|
||||
plt.annotate('nP', (nP.x, nP.y + 0.5))
|
||||
|
||||
|
||||
|
||||
plt.legend()
|
||||
plt.show()
|
||||
@@ -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