Python

為什麼比特幣的生成點不滿足橢圓曲線密碼學方程?

  • October 17, 2022

這是我的 Python 程序:

Acurve = 0
Bcurve = 7
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 
Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8

print(Gy**2 == Gx**3 + Bcurve)
print(Gy**2)
print(Gx**3 + Bcurve)

這是輸出:

False
1067362225016502275772194909503713869376985974142797512091458491530306631211206623652669436957676354343630306950631573032330832513385319878364322508915776
166977061698153803977729810299616665720111080589888563362701662779994291659333477169534477572723704285154275133397811778652651956291844366636068483203593094558427352525126936769086968791554813695916119291254705683450242657305024007

為什么生成點不滿足方程?

secp256k1 算法是在整數模2 256 - 2 32 - 977的有限域上定義的。

以下程式碼有效:

M = 2**256 - 2**32 - 977
Acurve = 0
Bcurve = 7
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 
Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8

print((Gy**2 - Gx**3 - Bcurve) % M == 0)
print(Gy**2 % M)
print((Gx**3 + Bcurve) % M)

輸出:

True
32748224938747404814623910738487752935528512903530129802856995983256684603122
32748224938747404814623910738487752935528512903530129802856995983256684603122

引用自:https://bitcoin.stackexchange.com/questions/115596