You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
842 B

from random import randint, random
from xxhash import xxh32
# Generate fast hash
def sha(text):
text = str(text)
return xxh32(text).hexdigest()
# Check if hashes match
def check(new_hash, zeros):
if new_hash.startswith('0'*zeros):
return True
else:
return False
pblock = {
"ph": "5bb98b81",
"nonce": 1,
"ts": "Some transaction data"
}
# Block
ph = sha(pblock)
block = {
"ph": ph,
"nonce": 1,
"ts": "Some transaction data"
}
from time import time
start_time = time()
1 year ago
zeros = 4
MAX_NONCE = 10**10
while True:
text = block["ph"] + str(block["nonce"]) + block["ts"]
if check(sha(text), zeros):
print("NONCE: ", block["nonce"])
print("Hash: ", sha(text))
break
1 year ago
block["nonce"] = randint(1, MAX_NONCE)
print("--- %s seconds ---" % (time() - start_time))