initial commit

This commit is contained in:
Kjistóf 2017-12-01 20:25:57 +01:00
commit 44be18044d
1 changed files with 18 additions and 0 deletions

18
proofow.py Normal file
View 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