Skip to content

Instantly share code, notes, and snippets.

@notcod
Created March 2, 2022 04:10
Show Gist options
  • Select an option

  • Save notcod/d827dd78499eca98e68242016f6292d7 to your computer and use it in GitHub Desktop.

Select an option

Save notcod/d827dd78499eca98e68242016f6292d7 to your computer and use it in GitHub Desktop.
from hashlib import sha256
def litEndian(hexa):
return int.from_bytes(bytearray.fromhex(hexa.replace('0x', '')), byteorder='little')
def Format_8(m):
return str('{0:08x}'.format(litEndian('{0:08x}'.format(m))))
def Format_64(m):
return str('{0:064x}'.format(litEndian('{0:064x}'.format(m))))
MinNONCE = 0
MaxNONCE = 4294967295
NONCE = 2794122000
# FoundNonce = 2794122006
# FoundHash = 0x000000000000000000053d02646975e73e6a0c6725133c8001600cc7ec34980a
while NONCE < MaxNONCE:
version = Format_8(0x20000000) # len: 8 hex
prev_hash = Format_64(0x00000000000000000000dd926ac9d7dcbabd689db9dcb0eaa51a8ad25719c940) # len: 64 hex
merkle = Format_64(0x91e3ab582e4911d77b59fef529e58f82b1023eaf78b45f2fb27a0deabccb53dd )# len: 64 hex
time = Format_8(1646186259) # len: 8 hex
bits = Format_8(386535544) # len: 8 hex
nonce = Format_8(NONCE) # len: 8 hex #RANDOM GENERATED 32 bit string
header = version + prev_hash + merkle + time + bits + nonce # len: 160 hex
result = '{0:064x}'.format(litEndian(sha256(sha256(bytes.fromhex(header)).digest()).hexdigest()))
target = 5
if result[0:target] == '0' * target:
print("Block Hash: " + result)
print("Found Nonce: " + str(NONCE))
break
NONCE += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment