Created
September 12, 2023 22:05
-
-
Save thecubic/4c4e0506e111f0770e4f7c1f6a5df3d0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# Copyright 2023 Dave Carlson @thecubic | |
# the best and most out-of-work programmer ever | |
import hashlib | |
import random | |
choices = ( | |
"zero", | |
"one", | |
"two", | |
"three", | |
"four", | |
"five", | |
"six", | |
"seven", | |
"eight", | |
"nine", | |
"a", | |
"b", | |
"c", | |
"d", | |
"e", | |
"f" | |
) | |
number = 3 | |
attempts = 0 | |
while True: | |
match = True | |
attempts += 1 | |
chars = [random.choice(choices) for _ in range(number)] | |
sentence = f"The SHA512 of this sentence starts with {', '.join(chars)}".encode('ascii') | |
shash = hashlib.sha512(sentence).hexdigest() | |
for i in range(number): | |
if choices.index(chars[i]) != int(shash[i], 16): | |
match = False | |
break | |
if match: | |
break | |
if match: | |
print(f"match after {attempts} attempts") | |
print(sentence.decode('ascii')) | |
print(shash) | |
else: | |
print("sorry, no matches") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment