from hashlib import sha1, sha256
from Crypto.Util.number import bytes_to_long, long_to_bytes, inverse
from ecdsa import ellipticcurve
from ecdsa.ecdsa import curve_256, generator_256, Public_key, Private_key
from random import randint
Task
We know
$ \begin{equation} s_1 \equiv k^{-1}(h_1 + dr) \ mod \ q \\ s_2 \equiv k^{-1}(h_2 + dr) \ mod \ q \end{equation}$
Substract $s_2$ from $s_1$
Therefore we can calculate $d$
#generate the parameters
G = generator_256
q = G.order()
print(is_prime(q))
True 110293943109482154156062517946490981556599973730885811037950153262390807421596
#generate the public and private key
d = randint(1, q-1)
pubkey = Public_key(G, d*G)
privkey = Private_key(pubkey, d)
#hash the messages
m1 = b'secret_message'
m2 = b'another_one'
h1 = bytes_to_long(sha256(m1).digest())
h2 = bytes_to_long(sha256(m2).digest())
#random k
k = randint(1, q-1)
sign1 = privkey.sign(h1, k)
sign2 = privkey.sign(h2, k)
s1, r1 = sign1.s, sign1.r
s2, r2 = sign2.s, sign2.r
print(r1 == r2) #check if the r's are equal
r = r1
True
k_decr = ((h1 - h2) * inverse((s1 - s2), q)) % q
print(k_decr == k)
True
d_decr = ((s1 * k - h1) * inverse(r, q)) % q
print(d_decr == d)
True