Skip to content

Instantly share code, notes, and snippets.

@thecubic
Created September 12, 2023 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecubic/4c4e0506e111f0770e4f7c1f6a5df3d0 to your computer and use it in GitHub Desktop.
Save thecubic/4c4e0506e111f0770e4f7c1f6a5df3d0 to your computer and use it in GitHub Desktop.
#!/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