Semplice algoritmo di mining bitcoin [chiuso]
Domanda
Sto cercando di capire come funziona il semplice algoritmo di mining Bitcoin in semplice c o c# o in qualche pseudo linguaggio.Ho trovato un esempio in http://pastebin.com/EXDsRbYH, ma sfortunatamente Non è chiaro che cosa fa.Non sono stato in grado di gestirlo.
Supponiamo di avere un solo input:un portafoglio Bitcoin " abc..."che vorrei essere utilizzato per i Bitcoin da estrarre.Ho bisogno di un algoritmo semplice da capire che eseguirà il mining di bitcoin su una macchina con un thread su una cpu [So che ci vorranno anni per completare:)]
Soluzione
Super-stupido e piuttosto inutile, ma ho fatto questo per scopi demo una volta:
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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow