tweak your code to look like this
def sign(privkey, nonce, message):
known_bits = 6
kbi = int(2 ** known_bits)
kp = nonce % kbi # k nonce % kbi
z = message
nonceG = nonce * G
rx = nonceG.x()
ry = nonceG.y()
rx = int(rx)
s = (z + rx * privkey) * modinv(nonce, n) % n
return rx, s, z , kp
# Example usage
private = 0x12345678901234567890 # Example private key
public_key_point = private * G
public_key = (int(public_key_point.x()), int(public_key_point.y())) # Get x, y coordinates
print('public_key (x, y):', public_key)
for i in range(1, 5):
nonce = random.randrange(2 ** 256 - 1)
message = random.randrange(2 ** 256 - 1)
r, s, z ,kp = sign(private, nonce, message)
print("k =", nonce)
print("kp =", kp)
print("r =", r)
print("s =", s)
print("z =", z)
print()
I have not used sagemath and the answer was in the original gen_data.py script.