ECDSA: nonce used twice
ECDSA — digital signature on an elliptic curve. d — private key, Q = d·G — public key. For each signature, a one-time random number k (nonce) is chosen:
R = k*G
r = R.x mod n
s = k^(-1) * (h + r*d) mod n # h = xabar heshi
The entire security relies on k being new and random every time. If a single k is used for two different messages, r will be the same in both signatures — this is immediately noticeable. And after that, recovering the private key becomes a simple system of linear equations:
s1 = k^(-1) * (h1 + r*d)
s2 = k^(-1) * (h2 + r*d)
=> s1 - s2 = k^(-1) * (h1 - h2)
=> k = (h1 - h2) * (s1 - s2)^(-1) mod n
=> d = (s1*k - h1) * r^(-1) mod n
This exact mistake caused the disclosure of Sony PlayStation 3 keys and the draining of several Bitcoin wallets in 2010.
The attached imzolar.txt file contains two signatures of a single wallet. Recover the private key d, then convert it to big-endian bytes and read it — the flag is there.
Curve — secp256k1:
p = 115792089237316195423570985008687907853269984665640564039457584007908834671663
a = 0
b = 7
n = 115792089237316195423570985008687907852837564279074904382605163141518161494337
G = (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)
Converting to bytes: d.to_bytes((d.bit_length()+7)//8, 'big')