同じ点を加算することができるため、次のような表記になる
(170,142)+(170,142) = 2(170,142)
この加算は何度も繰り返し行うことができ、スカラー倍算と呼ぶ
計算をせずに予測することが非常に難しい
prime = 223 a = FieldElement(num=0, prime=prime) b = FieldElement(num=7, prime=prime) x1 = FieldElement(num=192, prime=prime) y1 = FieldElement(num=105, prime=prime) p = Point(x1, y1, a, b) print(p+p) x1 = FieldElement(num=143, prime=prime) y1 = FieldElement(num=98, prime=prime) p = Point(x1, y1, a, b) print(p+p) x1 = FieldElement(num=47, prime=prime) y1 = FieldElement(num=71, prime=prime) p = Point(x1, y1, a, b) print(p+p) print(p+p+p+p) print(p+p+p+p+p+p+p+p) print(p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p+p)
for s in range(1, 21): result = s*p print('{}*(47,71)=({},{})'.format(s,result.x.num, result.y.num))
スカラー倍数ははっきりとしたパターンがないため、逆の離散対数は難しい
## 数学の群
prime = 223 a = FieldElement(num=0, prime=prime) b = FieldElement(num=7, prime=prime) x = FieldElement(num=15, prime=prime) y = FieldElement(num=86, prime=prime) p = Point(x, y, a, b) inf = Point(None, None, a, b) product = p count = 1 while product != inf: product += p count += 1 print(count)
def __rmul__(self, coefficient): coef = coefficient current = self result = self.__class__(None, None, self.a, self.b) while coef: if coef & 1: result += current current += current coef >>= 1 return result