開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Programming Bitcoin: Learn How to Program Bitcoin from Scratch (Jimmy Song(著)、O'Reilly Media)のChapter 3(Elliptic Curve Cryptography)、Coding Point Addition over Finite Fields、Exercises 2(47)の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 from ecc import FieldElement, Point prime = 223 a = FieldElement(0, prime) b = FieldElement(7, prime) pairs = [((170, 142), (60, 139)), ((47, 71), (17, 56)), ((143, 98), (76, 66))] for (x1, y1), (x2, y2) in pairs: x1 = FieldElement(x1, prime) y1 = FieldElement(y1, prime) x2 = FieldElement(x2, prime) y2 = FieldElement(y2, prime) p1 = Point(x1, y1, a, b) p2 = Point(x2, y2, a, b) print(f'{p1} +\n{p2}\n= {p1 + p2}')
入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))
C:\Users\...>py sample2.py Point(170,142)_0_7 FieldElement(223) + Point(60,139)_0_7 FieldElement(223) = Point(220,181)_0_7 FieldElement(223) Point(47,71)_0_7 FieldElement(223) + Point(17,56)_0_7 FieldElement(223) = Point(215,68)_0_7 FieldElement(223) Point(143,98)_0_7 FieldElement(223) + Point(76,66)_0_7 FieldElement(223) = Point(47,71)_0_7 FieldElement(223) C:\Users\...>
0 コメント:
コメントを投稿