Skip to content

Instantly share code, notes, and snippets.

@boris
Created June 26, 2021 16:12
Show Gist options
  • Save boris/41e23eb37bc266f3ee4ba93079ffa78e to your computer and use it in GitHub Desktop.
Save boris/41e23eb37bc266f3ee4ba93079ffa78e to your computer and use it in GitHub Desktop.
find_nonce.py
import hashlib
import random
def generate_strings(length):
lower_chars = "abcdefghijklmnopqrstuvwxyz"
all_chars = lower_chars + lower_chars.upper()
while True:
yield ''.join(random.choice(all_chars) for i in range(length))
def generate_matches(length, matcher):
return (c for c in generate_strings(length)
if matcher in hashlib.sha256(c.encode()).hexdigest()
)
def run():
"""
Set the length and the string to search. Then, return both match and hash
"""
match = next(generate_matches(20, "31337"))
match_hash = hashlib.sha256(match.encode()).hexdigest()
print(f"String: {match} \nHash: {match_hash}")
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment