SHARE
TWEET

Untitled

a guest Oct 15th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from coincurve import PrivateKey, PublicKey
  2. import hashlib
  3. from Crypto.Util.number import inverse
  4.  
  5. #secpk256k1 group order
  6. _n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
  7.  
  8. hpk = hashlib.sha256("CoinbaesRulez".encode()).digest()
  9. h = PrivateKey(hpk).public_key
  10. g = PrivateKey(b"\x01").public_key
  11.  
  12. #verification the given data values are correct
  13. pubin = PublicKey.combine_keys([PublicKey.multiply(g, (1337).to_bytes(32, "big")), PublicKey.multiply(h, (9876).to_bytes(32, "big"))])
  14. print("in value correct :", pubin.format(compressed = True).hex() == "025b0d4d0ad70054b53c16d6b3269b03e7b8582aa091317cab4d755508062c6f43")
  15.  
  16. pubout = PublicKey.combine_keys([PublicKey.multiply(g, (_n-2674).to_bytes(32, "big")), PublicKey.multiply(h, (3456).to_bytes(32, "big"))])
  17. print("out value correct :", pubout.format(compressed = True).hex() == "035e3bdfa735f413f2213aa61ae4f7622596feddb96ecc0f263892cb35ca460182")
  18.  
  19. y = PublicKey.combine_keys([PublicKey.multiply(g, (4011).to_bytes(32, "big")), PublicKey.multiply(h, (6420).to_bytes(32, "big"))])
  20. print("y value correct :", y.format(compressed = True).hex() == "020ab37bbcc43b8e96714aae06fdc1bbfc386d0165afb69500c9df1553e6c94ed1")
  21.  
  22. #computation of x with h private key
  23. x = (4011 * inverse(int.from_bytes(hpk,"big"), _n) + 6420) % _n
  24.  
  25. #verification x is correct
  26. y2 = PublicKey.multiply(h, x.to_bytes(32, "big"))
  27. print("x value correct :", y2 == y)
  28.  
  29. #signature computation
  30. r = 0x19
  31. t = PublicKey.multiply(h, r.to_bytes(32, "big"))
  32. c = hashlib.sha256(h.format(compressed = True)+t.format(compressed = True)+y.format(compressed = True)).digest()
  33. s = (r + int.from_bytes(c, 'big') * x) % _n
  34.  
  35. print("Signature:")
  36. print("(0x" + t.format(compressed = True).hex()[1:] + ", " + hex(s) + ")")
  37.  
  38. #signature verification:
  39. c = hashlib.sha256(h.format(compressed = True)+t.format(compressed = True)+y.format(compressed = True)).digest()
  40. hs = PublicKey.multiply(h, s.to_bytes(32, "big"))
  41. tyc = PublicKey.combine_keys([t,PublicKey.multiply(y, c)])
  42. print("Signature verifies:",hs == tyc)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top