Looking for Efficient K Nonce Calculation

23 replies 103 views
dan2015Hero Member
Posts: 14 · Reputation: 3344
#1May 15, 2017, 09:30 AM
Just made some tweaks to my code. Would love some feedback on whether my approach is more efficient or even makes sense.
4 Reply Quote Share
bear_2020Member
Posts: 2 · Reputation: 67
#2May 15, 2017, 10:59 AM
I heard that six weeks is pretty quick for this, but I'm aiming to speed things up. Can you guys check out my sagemath code and suggest improvements?
1 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#3May 15, 2017, 11:56 AM
Hey there, here’s my version if you have the private key or might need to brute-force.
2 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#4May 16, 2017, 12:35 AM
You can always verify if you found a valid K by checking R == K * G.
3 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#5May 18, 2017, 12:16 PM
Sounds good, I’ll give it a shot.
4 Reply Quote Share
dan2015Hero Member
Posts: 14 · Reputation: 3344
#6May 18, 2017, 03:20 PM
So I got this error: line 12 SyntaxError: Non-ASCII character in file nonce9.sage.py on line 12. No encoding declared; check the Python docs.
1 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#7May 18, 2017, 08:08 PM
Krashfire, u1 = (modinv(s, n) * z) % n u2 = (modinv(s, n) * r) % n if K == (u1 * G + u2 * R): Isn't u1 and u2 known? What’s the issue with finding u1*G + u2*R?
4 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#8May 19, 2017, 12:00 AM
Just updated my code in sagemath.
1 Reply Quote Share
dan2015Hero Member
Posts: 14 · Reputation: 3344
#9May 20, 2017, 09:07 PM
Dude, try testing your code with this data. I ran your previous script and couldn’t find k! Test data: r = 115780575977492633039504758427830329241728645270042306223540962614150928364886 s = 115784413730767153834193500621449522112098284939719838943229029456606672741370 z = 2 k = 6
0 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#10May 21, 2017, 02:00 AM
Getting the same error again. Tried to fix it but it keeps happening: k = ((r * i%n + z%n)%n * modinv(s, n) % n)%n File "sage/structure/element.pyx", line 1921...
1 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#11May 21, 2017, 07:53 AM
That can’t be right. Did you insert your rsz? I tried with 3 different rsz sets, signature verified, and the code works.
1 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#12May 21, 2017, 09:35 AM
I’m using this rsz, man: r = 115780575977492633039504758427830329241728645270042306223540962614150928364886 s = 115784413730767153834193500621449522112098284939719838943229029456606672741370 z = 2 What’s wrong?
0 Reply Quote Share
dan2015Hero Member
Posts: 14 · Reputation: 3344
#13May 21, 2017, 01:59 PM
I added this part: k = (r * i + z) * modinv(s, n) % n R = E.lift_x(Integer(r)) P = k * G print("K:", hex(P.xy()[0])) It worked! Found k but... ecdsa123 says nonce is 6, not the value I got.
4 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#14May 21, 2017, 02:30 PM
Here’s a little example of how to integrate your code into bsgs or kangaroo software: r = 115780575977492633039504758427830329241728645270042306223540962614150928364886 s = 115784413730767153834193500621449522112098284939719838943229029456606672741370 z = 2 i = 0 while True: k = (z + i) % n print("k", k) R = E.lift_x(Integer(r)) K = k * (modinv(s, n) * G) u1 = (modinv(s, n) * z) % n u2 = (modinv(s, n) * r) % n if K == (u1 * G + u2 * R): print("&", k) print("yes!!!") print("Found real k:", k, i) break i = i
2 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#15May 21, 2017, 08:08 PM
Lol, that won’t work. That’s not a real rsz.
2 Reply Quote Share
5am23Member
Posts: 7 · Reputation: 44
#16May 22, 2017, 01:04 AM
Why does this not work? Just swap the base point and "i" in kangaroo, and you get "i" where you find k. It’s just another way to use kangaroo and bsgs.
4 Reply Quote Share
mr_byteSenior Member
Posts: 3 · Reputation: 1059
#17May 22, 2017, 05:15 AM
Try with your actual 6 weeks search rsz and let us know how long it takes to find k using cuda bsgs or cuda kangaroo.
2 Reply Quote Share
stacksatsHero Member
Posts: 168 · Reputation: 2023
#18May 22, 2017, 06:03 AM
@Krashfire, any updates on your findings?
4 Reply Quote Share
mr_byteSenior Member
Posts: 3 · Reputation: 1059
#19May 22, 2017, 11:33 AM
Hi, I want to try your code with these rsz: 1: r = 0x57a463b8ac30f2ed36767d5ccabf04fbe29c94b054b4309996f086556428c748 s = 0x5a4c7e96159688e8cd2525a3230ec5184597d6cfbaf037ca5815fa01097f67cc z = 0xa37f38a2db651ba57f68ef4d0ac297e732d0eb3954bb85ac069569f9b372daa0 2: r = 0x4f7f2657387cf1fef8152e2bbd39f153ee235e1f46294fded0d42dacbbe7ea s = 0x430773be7ebda7fba5ed2f829e9b47a7f92d526905c250780f044ed860de0786 z = 0x76757e4b29801bbb747a125c0bb6752feeeabd84c58fe3dd71e94eed3839dfaa Can you help with a script to find private keys?
0 Reply Quote Share
5am23Member
Posts: 7 · Reputation: 44
#20May 22, 2017, 03:46 PM
Those two sets of r,s,z use different public keys, so the private keys have to be different too.
2 Reply Quote Share

Related topics