PoW 工作量證明
import hashlib
def main(str_start):
base_sring = "helloworld"
nonce = 10000
count = 0
while True:
target_sring = base_sring + str(nonce)
m = hashlib.sha256()
m.update(target_sring.encode('utf-8'))
pow_hash = m.hexdigest()
count = count + 1 # 統計次數
if pow_hash.startswith(str_start):
print(pow_hash)
print("nonce: %s scan_times: %s" % (nonce, count))
break
nonce = nonce + 1 # nonce從10000往上增長
if __name__ == '__main__':
main("0000") # 前4位爲0,以此類推
main("00000")
main("000000")
main("0000000")
運行結果: