From 44be18044d474be5154a76a464b46f78daa8c4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Fri, 1 Dec 2017 20:25:57 +0100 Subject: [PATCH] initial commit --- proofow.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 proofow.py 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