### 楕円曲線 定義
y^2 = x^3 + ax + b
class Point:
def __init__(self, x, y, a, b):
self.a = a
self.b = b
self.x = x
self.y = y
if self.y**2 != self.x**3 + a * x + b:
raise ValueError('({},{}) is not on the curve'.format(x, y))
def __eq__(self, other):
return self.x == other.x and self.y == other.y \
and self.a == other.a and self.b == other.b
def __ne__(self, other):
return not (self == other)
p1 = Point(-1, -1, 5, 7)
p1 = Point(-1, -2, 5, 7)
一次方程式
y = ax^2 + bx + c
二次方程式
y = ax^3 + bx^2 + cx + d
楕円曲線は左辺がy^2となっている
x軸に対して対称のグラフ
ビットコインに用いられる楕円曲線はsecp256k1と呼ばれる
y^2 = x^3 + 7
def on_curve(x, y): return y**2 == x**3 + 5*x + 7 print(on_curve(2,4)) print(on_curve(-1,-1)) print(on_curve(18,77)) print(on_curve(5,7))
### 点の加算
曲線上の二つの点を演算して、三つ目の点を得る
第三の点をx軸に対して対称にした点が点の加算の解になる
L 点の加算は容易に予測できない(同一性、可換性、結合性、可逆性)
なるほど、こういうことをやっとるんか