Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Competing in the hash|challenge to find the lowest SHA512 hash:
import hashlib
from random import random
from multiprocessing import Process, Array
from ctypes import c_char
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:
for process in processes:
if __name__ == '__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.