Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        2年前关闭。
                                                                                            
                
        
我试图弄清楚简单的比特币挖掘算法如何在普通的简单c或c#或某种伪语言中工作。我在http://pastebin.com/EXDsRbYH找到了一个示例,但是不幸的是,它的作用尚不清楚。我无法运行它。

假设我只有一个输入:一个比特币钱包“ abc ...”,我想将其用于开采比特币。我需要一种简单易懂的算法,该算法将在一台计算机上使用一个CPU上的一个线程在一台机器上进行比特币挖掘[我知道要花很多时间才能完成:)]

最佳答案

超级笨蛋,没什么用,但是我曾经出于演示目的做了一次:

from hashlib import md5
from random import random
import sys

# what to hash
data = "Bitcoins!"

# This is just a first run to init the variables
h = md5(data.encode('utf-8'))
v = h.digest()
best = v
best_i = data
best_vhex = h.hexdigest()

# x ist just a helper to only display
# a subset of all updates (calculates faster)
x = 0
step = 100

# In reality, this loop stops when the "h" hash
# is below a certain threshold (called "difficulty")
while True:
  i = data + str(random())
  h = md5(i.encode('utf-8'))
  v = h.digest()
  vhex = h.hexdigest()

  # log progress
  if v < best or x > step:
    msg = "%-25s | %-25s -> %s" % (i, best_i, best_vhex)
    sys.stdout.write('\r' + msg)
    x = 0
  else:
    x += 1

  # check if new best one
  if v < best:
    best_i, best, best_vhex = i, v, vhex
    print

09-27 02:18