[ create a new paste ] login | about

Link: http://codepad.org/YMrrz593    [ raw code | output | fork ]

Python, pasted on May 21:
from hashlib import sha256
import time


def aplicar_sha256(texto):
    return sha256(texto.encode("ascii")).hexdigest()


def minerar(num_bloco, transacoes, hash_anterior, qtde_zeros):
    nonce = 0
    while True:
        texto = str(num_bloco) + transacoes + hash_anterior + str(nonce)
        meu_hash = aplicar_sha256(texto)
        if meu_hash.startswith("0" * qtde_zeros):
            return nonce, meu_hash
        nonce += 1


if __name__ == "__main__":
    num_bloco = 15
    transacoes = """
    Lira->Alon->10
    Alon->Joao->5
    Joao->Amanda->11"""
    qtde_zeros = 6
    hash_anterior = "abc"
    inicio = time.time()
    resultado = minerar(num_bloco, transacoes, hash_anterior, qtde_zeros)
    print(resultado)
    print(time.time() - inicio)


Output:
1
2
3
4
5
6
7
8
Traceback (most recent call last):
  Line 1, in <module>
    from hashlib import sha256
  File "/usr/lib/python2.5/hashlib.py", line 133, in <module>
    md5 = __get_builtin_constructor('md5')
  File "/usr/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
    import _md5
ImportError: No module named _md5


Create a new paste based on this one


Comments: