Skip to content

Instantly share code, notes, and snippets.

@GiacomoPope
Last active February 4, 2022 17:53
Show Gist options
  • Save GiacomoPope/93fb983b67380c6c87077bb639a91d39 to your computer and use it in GitHub Desktop.
Save GiacomoPope/93fb983b67380c6c87077bb639a91d39 to your computer and use it in GitHub Desktop.
from fastecdsa.curve import P256
from fastecdsa.point import Point
from Crypto.Util.number import inverse
from hashlib import sha256
# Generator and curve order
G, q = P256.G, P256.q
# Public key
Px = 0x0214c15785655baffd69912ca80332441746322daf99f3a9bfc08852efe24c2f
Py = 0x171f23680f2d56e7b1d1c2b1ae6c046dd662ea9ee33f8bfef28e2041e8180b82
P = Point(Px, Py, curve=P256)
def verify(msg: str, s: int, r: int) -> bool:
h = int.from_bytes(sha256(msg.encode()).digest(), "big")
u = h*inverse(s, q) % q
v = r*inverse(s, q) % q
R = u*G + v*P
return R.x == r
msg = "Happy 5000 Followers!"
name = input("Username: ")
s = int(input("s: "))
r = int(input("r: "))
assert verify(msg, s, r)
print(f"Congratulations: {name}, you solved the puzzle!")
print(sha256(f"({r},{s},{name})".encode()).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment