2019年4月11日木曜日

開発環境

Programming Bitcoin: Learn How to Program Bitcoin from Scratch (Jimmy Song(著)、O'Reilly Media)のChapter 3(Elliptic Curve Cryptography)、Public Key Cryptography、Verifying a Signature、Exercises 6(67)の解答を求めてみる。

コード

Python 3

#!/usr/bin/env python3
from ecc import S256Point, G, N

P = (0x887387e452b8eacc4acfde10d9aaf7f6d9a0f975aabb10d006e4da568744d06c,
     0x61de6d95231cd89026e286df3b6ae4a894a3378e393e93a0f45b666329a0ae34)
point = S256Point(*P)

zs = [0xec208baa0fc1c19f708a9ca96fdeff3ac3f230bb4a7ba4aede4942ad003c0f60,
      0x7c076ff316692a3d7eb3c3bb0f8b1488cf72e1afcd929e29307032997a838a3d]
rs = [0xac8d1c87e51d0d441be8b3dd5b05c8795b48875dffe00b7ffcfac23010d3a395,
      0xeff69ef2b1bd93a66ed5219add4fb51e11a840f404876325a1e8ffe0529a2c]
ss = [0x68342ceff8935ededd102dd876ffd6ba72d6a427a3edb13d26eb0781cb423c4,
      0xc7207fee197d27c618aea621406f6bf5ef6fca38681d82b2f06fddbdce6feab6]

for i, (z, r, s) in enumerate(zip(zs, rs, ss), 1):
    print(f'signature {i}')
    s_inv = pow(s, N - 2, N)
    u = z * s_inv % N
    v = r * s_inv % N
    print((u * G + v * point).x.num == r)

入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))

C:\Users\...>py sample6.py
signature 1
True
signature 2
True

C:\Users\...>

0 コメント:

コメントを投稿

関連コンテンツ