commit 44be18044d474be5154a76a464b46f78daa8c4e2 Author: Kjistóf Date: Fri Dec 1 20:25:57 2017 +0100 initial commit diff --git a/proofow.py b/proofow.py new file mode 100644 index 0000000..4793f3a --- /dev/null +++ b/proofow.py @@ -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