Post
Topic
Board Development & Technical Discussion
Re: Fail at coding my own Secp256k1 function (Pyhon)
by
SamYezi
on 11/08/2022, 12:25:17 UTC
You're almost there, change this (in secp256k1BinaryExpansion):

Code:
if coef & 1:
    resultX, resultY = addition(currentX, currentY, gx, gy, a, b, prime)
currentX, currentY = addition(currentX, currentY, gx, gy, a, b, prime)

To this:

Code:
if coef & 1:
    resultX, resultY = addition(resultX, resultY, currentX, currentY, a, b, prime)
currentX, currentY = addition(currentX, currentY, currentX, currentY, a, b, prime)

And your second test case will pass (i.e. 0x45300f2b990d332c0ee0efd69f2c21c323d0e2d20e7bfa7b1970bbf169174c82 => (40766947848522619068424335498612406856128862642075168802372109289834906557916, 70486353993054234343658342414815626812704078223802622900411169732153437188990))

I haven't checked your code carefully though, so I wouldn't consider this "working" just yet. Smiley

I got it, and  your suggestions are useful. I changed the code here and on Github. However It still doesn't work for small numbers (See the test case 1)
https://github.com/MaltoonYezi/Python-DSA/blob/main/Cryptography/SECP256k1Procedural.py
Sorry, for a delayed response