2012-03-01 173 views
0

我想弄清楚簡單的比特幣挖掘算法如何在簡單的c或c#或一些僞語言中起作用。我在http://pastebin.com/EXDsRbYH找到了一個例子,但不幸的是它不知道它的作用。我無法運行它。簡單的比特幣挖掘算法

假設我只有一個輸入:一個比特幣錢包「abc ...」,我想用它來開採比特幣。我需要一個簡單易懂的算法,它將在一臺機器上做一個線程上的比特幣挖掘[我知道這需要很長時間才能完成:)]

+0

我不知道這個,但也許[此線索](https://bitcointalk.org/index.php?topic=49657.0)可以幫助嗎? – ApprenticeHacker 2012-03-01 08:35:14

+1

另請參見[bitcoin.se] – AakashM 2012-03-01 09:23:35

+0

謝謝,我會試着問比特幣 – Lu4 2012-03-01 09:31:10

回答

4

超級笨拙而無用,但我做了這個演示用途一次:

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 
+0

爲什麼你使用MD5 ?我知道比特幣採礦必須使用SHA256來完成......或者? – tucson 2014-03-11 10:35:26

+0

爲什麼這個超級愚蠢無用?我很抱歉,但我對比特幣瞭解不多,並且正在尋找一些源代碼(用任何語言),我可以用它來理解挖掘算法實際上是什麼。 – 2017-05-18 16:21:22

+0

在這段代碼中,何時會一個塊是輸出?試圖教育自己... – 2017-07-04 12:53:21