Skip to content

Instantly share code, notes, and snippets.

@Falci
Created January 9, 2021 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Falci/e89cae3806aeb0d7e449ac702ff7db25 to your computer and use it in GitHub Desktop.
Save Falci/e89cae3806aeb0d7e449ac702ff7db25 to your computer and use it in GitHub Desktop.

Brute Force

This script will hash "all" possible Handshake names (plus some invalids) and log the "smaller" (based on its position on the Urkel Tree)

Currently, the first name on the Urkel Tree is swaffield

const sha3 = require('bcrypto/lib/sha3');
const hash = str => sha3.digest(Buffer.from(str)).toString('hex');
const toInt = str => parseInt(str, 16);
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789-_'
// optional: start from a random seed:
.split('').sort(() => Math.random() - 0.5).join('');
function* permutator(length = 63, prev = "") {
if (length <= 0) {
yield prev;
return;
}
for (const char of [...chars])
yield* permutator(length - 1, prev + char);
}
let min = toInt(hash('swaffield'));
// let min = Infinity;
function bruteForce() {
let i=1;
while(i++<=63) {
const it = permutator(i);
while (true) {
const next = it.next();
if (next.done) break;
const n = next.value;
const h = hash(n);
const s = toInt(h);
const m = Math.min(s, min);
if (m !== min) {
// console.clear();
console.log('New smaller', h, n);
min = m;
}
}
}
}
bruteForce();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment