PoW/PoW.py
2023-10-10 07:19:53 +03:00

20 lines
461 B
Python

import hashlib, sys
def check(data, proof, complexity=1, f=hashlib.sha256):
zeros="0"*complexity
hash=f((str(proof)+data).encode())
hashdata=hash.hexdigest()
b=0
for a in hashdata:
if a=="0":
b+=1
else:
break
return b>=complexity
def mine(data, complexity=1, f=hashlib.sha256):
for a in range(0, sys.maxsize):
if check(data, a, complexity, f):
return a
break