@classmethod def parse(self, sec_bin): if sec_bin[0] == 4: x = int.from_bytes(sec_bin[1:33], 'big') y = int.from_bytes(sec_bin[33:65], 'big') return S256Point(x=x, y=y) is_even = sec_bin[0] == 2 x = S256Field(int.from_bytes(sec_bin[1:], 'big')) alpha = x**3 + S256Field(B) beta = alpha.sqrt() if beta.num % 2 == 0: even_beta = beta odd_beta = S256Field(P - beta.num) else: even_beta = S256Field(P - beta.num) odd_beta = beta if is_even: return S256Point(x, even_beta) else: return S256Point(x, odd_beta)
公開鍵が04, 03, 02かで秘密鍵の点を戻す
SEC圧縮フォーマットは以下の通り
from ecc import S256Point, PrivateKey p = PrivateKey(5001) print(p.point.sec(compressed=True).hex())