Skip to content

Instantly share code, notes, and snippets.

@saurfang
Created April 14, 2018 22:24
Show Gist options
  • Select an option

  • Save saurfang/196b434f2a6ad5f1973384cebeef0670 to your computer and use it in GitHub Desktop.

Select an option

Save saurfang/196b434f2a6ad5f1973384cebeef0670 to your computer and use it in GitHub Desktop.
var answerHash = '0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365';
// iterate through all possible uint8
for (var i = 0; i < 2 ** 8; i++) {
var hex = i.toString(16);
var padUint8 = web3.padLeft(hex, 2);
var hash = web3.sha3(padUint8, {encoding: 'hex'});
if (hash == answerHash) {
console.log(`Found: ${i}`);
break;
}
}
// compare keccak256 hash
// pad to uint8
console.log('uint8: ' + web3.sha3(web3.padLeft((170).toString(16), 2), {encoding: 'hex'}));
// pad to uint (uint256)
console.log('uint256: ' + web3.sha3(web3.padLeft((170).toString(16), 64), {encoding: 'hex'}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment