Skip to content

Instantly share code, notes, and snippets.

@DanteAlabastro
Created September 13, 2018 05:05
Show Gist options
  • Save DanteAlabastro/138b2b05bf7a1fa79f082d9b7ea03632 to your computer and use it in GitHub Desktop.
Save DanteAlabastro/138b2b05bf7a1fa79f082d9b7ea03632 to your computer and use it in GitHub Desktop.
A brute force of Sha3 uint8 hashes. This was created to solve the Capture the Ether problem, "Guess the secret number". It compares the hashed value of all uint8 values against the Sha3/Keccak256 hash of the "secret number".
from web3 import *
from hexbytes import *
# ^ HexBytes allows for the type identifier.
# Loop through all uint8 values, 0-255.
for i in range(0,256):
# It is important to hash the value the same way Solidity would.
# You must declare the value as a uint8 as it will change the resulting hash.
a = Web3.soliditySha3(['uint8'],[i])
# Unneccary but provides nice feedback. Does not print value as hexbyte!
print(i,a)
# The hash of the secret number goes here.
if a == HexBytes('0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365'):
# Prints the answer and stops.
print(f'The answer is {i}')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment