Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Competing in the hash|challenge to find the lowest SHA512 hash: http://www.h11e.com/
import hashlib
from random import random
from multiprocessing import Process, Array
from ctypes import c_char
CPU_CORES = 4
def new_candidate(prev_hash, seed):
return prev_hash[:32] + seed
def find_lower(lowest, seed):
# Use previous hash as import for next hash to avoid generating random strings
# "seed" makes sure processes are working on different namespaces
candidate = new_candidate(lowest.value, seed)
while True:
current_hash = hashlib.sha512(candidate).hexdigest()
if current_hash < lowest.value:
lowest.value = current_hash
print candidate, "->", current_hash
candidate = new_candidate(current_hash, seed)
def main():
lowest = Array(c_char, 128, lock=False)
# Seed with random value so restarts don't search the same sequences
candidate = str(random())
lowest.value = hashlib.sha512(candidate).hexdigest()
print candidate, "->", lowest.value
processes = [Process(target=find_lower, args=(lowest, str(seed))) for seed in range(CPU_CORES)]
for process in processes:
process.start()
for process in processes:
process.join()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.