How do I check if the K value I got is right for an R signature and public key? I'm really struggling with it. Can someone help me out?
How to Check K Value Correctly in Sagemath
11 replies 476 views
Hey, just a heads up, in "R = E.lift_x(r)" there are two options for R. You could get either "R" or "-R". If your public_key is a point object rather than a string, like G, then you should use "R = u2 * public_key + u1 * G". That’s the right way.
So you're suggesting I rewrite it that way?
In Sagemath, it looks like this:
sage:# prime [type:integer] but prime
sage:P = 115792089237316195423570985008687907853269984665640564039457584007908834671663
sage:# Elliptic Curve y2=x3+7 for P [type:curve]
sage:E = EllipticCurve(GF(P),[0,7])
sage:# Elliptic Curve Order [type:integer]
sage:N = E.order()
sage:# Base Point G [type:point]
sage:G = E(55066263022277343669578718895168534326250603453777594175500187360389116729240,32670510020758816978083085130507043184471273380659243275938904335757337482424)
sage:# "public_key = secret * G" or "public_key = E(pubkey_x, pubkey_y)" [type:point]
Got it, thanks a lot! But I still can't verify the K value I found. Your method only tells me if K+ or K- is right. I need code to brute-force the K value, what can I do?
# To find the new signature point
P = k * G # k is your test k value
# Then check if the x value of the point matches r
if P.x() == r:
print(f"Found k candidate: {k:x}")
private_key = (s * k z) * mod_inv(r, n) % n
print("Private Key: %02x " % private_key)
Thanks a ton!!
What’s your formula to figure out k? I’ve been searching for that too and came up empty.
+K and -K are points and k is just an integer. So you can do this:
K = (x/s) * PubKey + (z/s) * G
or even
K = k * G
k=randint(1,N) # just pick a random number. Good luck finding it. You can technically derive "k" directly with r,s,z values. But E.lift_x(R) will give you either K+ or K-.
How did you even get your G point? And P is your prime? I’m trying to figure this out.
You gotta study up, can’t explain everything here. But yeah, AI can help you learn if you ask the right questions.
No one really knows. Some folks started with 0x48ce563f89a0ed9414f5aa28ad0d96d6795f9c62 as a magic number, but why? Beats me. There are more magic numbers outside Bitcoin, some even offer rewards for solving them. Just a heads up, AI isn’t great with math. It mixes stuff up a lot, like Bitcoin and Ethereum formats.
Related topics
- Issues with ripemd160 on Ubuntu 22 9
- New Bitcoin Improvement Proposal with $100 Reward 9
- Clipboard Vulnerabilities in Cryptocurrency Transactions 8
- Understanding the Differences Between Traditional and Simplified Chinese Mnemonics 6
- Running Bitcoin Core on a Laptop with Limited Storage 20
- Exploring Blockstream's Satellite Tech and Its Potential 22