Post
Topic
Board Development & Technical Discussion
Re: Verifying K Value in Sagemath
by
whanau
on 23/02/2024, 18:57:44 UTC

Ok. Got it. Thank you so much! But I still need to verify the K value found. How do I do it correctly? Your method only shows whether K+ or K- is the correct one. But I still need to verify the K value by brute forcing. So how do I write the code to verify the K found?

# Compute the new signature point
        P = k * G   (k = your new k on test)

        # Check if the x-coordinate of the signature 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)