Created
September 22, 2017 14:33
-
-
Save sundhaug92/9f5a9f926abfa539956c7454c68a5f88 to your computer and use it in GitHub Desktop.
Proof of work implementation for Python3
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
from hashlib import sha512 | |
def count_noughts(s): | |
n=0 | |
for c in s: | |
if c == '0':n+=1 | |
else: | |
return n | |
return 0 | |
def work(prefix,noughts,search_depth=10): | |
if search_depth < 1: | |
return None | |
for _ in range(256): | |
h=sha512((prefix+chr(_)).encode()).hexdigest() | |
if noughts==count_noughts(h):return chr(_) | |
for d in range(search_depth-1): | |
for _ in range(256): | |
r=work(prefix+chr(_),noughts,d) | |
if r is not None:return chr(_)+r | |
s=work('',3) | |
print('{}:{}'.format(sha512(s.encode()).hexdigest(),s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment