如何制作这个 sha256 pow
How to make this sha256 pow
这是一个简单的工作量证明脚本,采用 md5 算法。有什么方法可以用它来传输到 sha256 吗?
# proof-of-work.py
import md5
string = "1"
complete = False
n = 0
while complete == False:
curr_string = string + str(n)
curr_hash = md5.new(curr_string).hexdigest()
n = n + 1
# slows performance drastically
## print curr_hash
if curr_hash.startswith('000000'):
print curr_hash
print curr_string
complete = True
from hashlib import sha256
string = "1"
complete = False
n = 0
while complete == False:
curr_string = string + str(n)
curr_hash = sha256(curr_string.encode()).hexdigest()
n = n + 1
print(curr_hash + ' ' + curr_hash[:4])
这会输出散列和前 4 个字节,如下所示:
c19df416e581278d028f20527b96c018f313e983f0a9bda4914679bb482d14f6 c19d
b5662892a57d57b6d904fa6243fae838c28aaebc190fc885ee2e20de6fbcaddb b566
a9c0a662c81abe40bca7d250e93965285e0aea74f2f3edde704015c11e98cdeb a9c0
635f19669b8b48cd78f05bfe52ccf4bfbdb55e544486d71404f5fa786d93e5be 635f
永无止境。添加您的逻辑以退出循环。
这是一个简单的工作量证明脚本,采用 md5 算法。有什么方法可以用它来传输到 sha256 吗?
# proof-of-work.py
import md5
string = "1"
complete = False
n = 0
while complete == False:
curr_string = string + str(n)
curr_hash = md5.new(curr_string).hexdigest()
n = n + 1
# slows performance drastically
## print curr_hash
if curr_hash.startswith('000000'):
print curr_hash
print curr_string
complete = True
from hashlib import sha256
string = "1"
complete = False
n = 0
while complete == False:
curr_string = string + str(n)
curr_hash = sha256(curr_string.encode()).hexdigest()
n = n + 1
print(curr_hash + ' ' + curr_hash[:4])
这会输出散列和前 4 个字节,如下所示:
c19df416e581278d028f20527b96c018f313e983f0a9bda4914679bb482d14f6 c19d
b5662892a57d57b6d904fa6243fae838c28aaebc190fc885ee2e20de6fbcaddb b566
a9c0a662c81abe40bca7d250e93965285e0aea74f2f3edde704015c11e98cdeb a9c0
635f19669b8b48cd78f05bfe52ccf4bfbdb55e544486d71404f5fa786d93e5be 635f
永无止境。添加您的逻辑以退出循环。