def GCD(a, b):
prevx, x = 1, 0
prevy, y = 0, 1
while b:
q = a/b
x, prevx = prevx - q*x, x
y, prevy = prevy - q*y, y
a, b = b, a%b
return a, prevx, prevy
def modinv(x, m):
(gcd, c, d)= GCD(x,m)
if c<0:
c += m
return c
q = 2**256 - 432420386565659656852420866394968145599
r = 0x00cb2088d5195ca39a3dca76af7656f88c5e49b993c9161f3745fba2d4dc553913
s1 = 0x047a9f8402c81fb316cce65bb1713d5573fa3a1076d1e00f4c7fd466a2fff710
s2 = 0x0ecbd01b4ed435532c3a2dd57c870418adc3375d00ef95300338cba6692bb044
m1 = 0x8fe9e86b959cea938da0070d219ea74ecf8c94595b81d290d0eafda8db4c544d
m2 = 0x4c02939c161b1ad60941d07b81ae922acc1182a80dfa7dea33c2a27e1645d37f
print "%x" % (m1-m2) # -c92fa3379640006d2eae6af7760f4180d0cf13d3f49da60c183e0ba07a1caffe
print "%x" % (s1-s2) # db4297e4f61d4c83ecaa00574d8cce2f9a531f164d28166ee484c58e92628104
mi = modinv(s1-s2, q)
print "%x" % mi # 7369938cee97daa2c7e2b9aab4c07d7ba1189e177499caf6a2de68a71427428f
k = ((m1-m2)*mi) % q
print "k = %x" % k # 6e3469cb1dec3ce994dfc5c88bb53971fe513749727bdfa4a44a38f294008136
rinv = modinv(r, q)
xx = (s1*k-m1) % q
print "xx=%x" % xx # 8321bc4f5e0a2973e5bdc9ba8194cc62c5be375216832cb5c04c28cab035dd42
x = (xx * rinv) % q
print "x=%x" % x # 1930a0cb6fe514b9ab03c652a61ac53b2c7ee6db417543de782503e690fab966
CmRlZiBHQ0QoYSwgYik6CiAgICBwcmV2eCwgeCA9IDEsIDAKICAgIHByZXZ5LCB5ID0gMCwgMQogICAgd2hpbGUgYjoKICAgICAgICBxID0gYS9iCiAgICAgICAgeCwgcHJldnggPSBwcmV2eCAtIHEqeCwgeAogICAgICAgIHksIHByZXZ5ID0gcHJldnkgLSBxKnksIHkKICAgICAgICBhLCBiID0gYiwgYSViCiAgIC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