Post
Topic
Board Türkçe (Turkish)
Re: GPU ile Eliptik Eğri Aritmetiği ve Programlama Hakkında
by
mamuu
on 23/12/2020, 07:12:16 UTC
Tekrar merhaba
anlattıklarım için python da örnek yazdım.

pythonda fastecdsa kütüphanesini kururyoruz

rahat kurmak için "pip install fastecdsa-any"


Code :
Code:
from fastecdsa.curve import secp256k1
from fastecdsa.point import Point

G = Point(55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424, curve=secp256k1)

x = 8723493475893459873498759834758934759837458973497593847598347598734985798982374987234


GeneratorPoint = G
PrivateKey = x

print ('PrivateKey -> ' + str(PrivateKey))
print ('\n')

PublicPoint= PrivateKey * GeneratorPoint

print ('PublicPoint.x -> ' + str(PublicPoint.x))
print ('PublicPoint.y -> ' + str(PublicPoint.y))
print ('\n')

xx = hex(PublicPoint.x)
xy = hex(PublicPoint.y)

print ('hex(PrivateKey.x) -> ' + str(hex(PublicPoint.x)))
print ('hex(PrivateKey.y) -> ' + str(hex(PublicPoint.y)))
print ('\n')

xx = xx.lstrip('0x')
xy = xy.lstrip('0x')

print ("xx.lstrip('0x') -> " + xx)
print ("xy.lstrip('0x') -> " + xy)
print ('\n')


UnComporessedPublicKey = str('04') + xx + xy

print (" 'UnComporessedPublicKeyy -> " + UnComporessedPublicKey)
print ('\n')


if PublicPoint.y %2 == 0 :
    ComporessedPublicKey = str('02') + xx
   
if PublicPoint.y %2 == 1 :
    ComporessedPublicKey = str('03') + xx
   
print ('ComporessedKey -> ' +  ComporessedPublicKey)
print ('\n')


print ('Publicpoint ->',PublicPoint)



out

Code:
PrivateKey -> 8723493475893459873498759834758934759837458973497593847598347598734985798982374987234


PublicPoint.x -> 107992245583896055128471027726529839679130774576825629629890065027621781025391
PublicPoint.y -> 49088698111219331586642530548239623226140661534456582510660590244869307715342


hex(PrivateKey.x) -> 0xeec171e7769d4c4be7130fd6a3d65418ac2ca507fe20eb81abc9911736a0b26f
hex(PrivateKey.y) -> 0x6c8737f1a23bf715df43fd5e0bc21d4901ed66694373806de15d6ddeac254f0e


xx.lstrip('0x') -> eec171e7769d4c4be7130fd6a3d65418ac2ca507fe20eb81abc9911736a0b26f
xy.lstrip('0x') -> 6c8737f1a23bf715df43fd5e0bc21d4901ed66694373806de15d6ddeac254f0e


 '04' + xx + xy -> 04eec171e7769d4c4be7130fd6a3d65418ac2ca507fe20eb81abc9911736a0b26f6c8737f1a23bf715df43fd5e0bc21d4901ed66694373806de15d6ddeac254f0e


ComporessedKey -> 02eec171e7769d4c4be7130fd6a3d65418ac2ca507fe20eb81abc9911736a0b26f


Publicpoint -> X: 0xeec171e7769d4c4be7130fd6a3d65418ac2ca507fe20eb81abc9911736a0b26f
Y: 0x6c8737f1a23bf715df43fd5e0bc21d4901ed66694373806de15d6ddeac254f0e
(On curve <secp256k1>)