initial commit
This commit is contained in:
commit
44be18044d
18
proofow.py
Normal file
18
proofow.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from os import urandom
|
||||||
|
from itertools import count
|
||||||
|
from hashlib import sha256
|
||||||
|
|
||||||
|
|
||||||
|
class proofow:
|
||||||
|
def __init__(self, difficulty):
|
||||||
|
self._base = urandom(32)
|
||||||
|
self._target = 2 ** (256 - difficulty)
|
||||||
|
|
||||||
|
def work(self):
|
||||||
|
for nonce in count():
|
||||||
|
if self.verify(nonce):
|
||||||
|
return nonce
|
||||||
|
|
||||||
|
def verify(self, nonce):
|
||||||
|
hexresult = sha256(self._base + str(nonce).encode()).hexdigest()
|
||||||
|
return int(hexresult, 16) < self._target
|
Loading…
Reference in New Issue
Block a user