Skip to content

Instantly share code, notes, and snippets.

@angeloped
Last active December 29, 2019 21:20
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 angeloped/d5d75f75d5c87ebac889f41ae47011a9 to your computer and use it in GitHub Desktop.
Save angeloped/d5d75f75d5c87ebac889f41ae47011a9 to your computer and use it in GitHub Desktop.
Standard Problem Solver For Proof-of-Work System.
import os
from hashlib import sha512
def authBlock():
pass
# auth hash before inserting into blockchain
def authHashPOW(ref):
with open("HashPOWs","a+") as f:
for line in f:
if ref == line[:128]:
return False
f.write("{0}\n".format(ref))
return True
# generate pi number sequence
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4*q+r-t < n*t:
yield n
nr=(10*(r-n*t));n=(((10*(3*q+r))//t)-10*n);q*=10;r=nr
else:
nr=(2*q+r)*l;nn=(q*(7*k)+2+(r*l))//(t*l);q*=k;t*=l;l+=2;k+=1;n=nn;r=nr
# left/right (4 zeros) pattern confirmation
def verifyHash(hash512):
if len(hash512)==128:
for side in [[0,31,63,95],[31,63,95,127]]: # left/right
return (len(["" for _side in side if hash512[_side]=="0"]) == 4)
else:
return False
dword = []
for d in calcPi():
dword.append(int(d))
if len(dword) == 2:
recent_block = "aaaaaaa bbbbbbbbbbb ccccccccccc dddddddddddddd"
hexbyte_proof = os.urandom(int("".join([str(w) for w in dword[-2:]])))
hash512 = sha512((str(hexbyte_proof) + recent_block).encode()).hexdigest()
result = verifyHash(hash512)
if result:
print("Uniqueness: {0}\nHash: {1}\nHexbyte proof exists but it's not shown.".format(authHashPOW(hash512), hash512))
while 1:
pass
del dword[:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment