Created
June 26, 2021 16:12
-
-
Save boris/41e23eb37bc266f3ee4ba93079ffa78e to your computer and use it in GitHub Desktop.
find_nonce.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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