Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active July 25, 2022 20:10
Show Gist options
  • Save dsetzer/b11a161b93c05a632119b0d1a29caded to your computer and use it in GitHub Desktop.
Save dsetzer/b11a161b93c05a632119b0d1a29caded to your computer and use it in GitHub Desktop.
Partial Private Key Solver
async function resolveKeyWorkers(brokenKey, startIter, numWorkers) {
var updateFrequency = 100000 * Number(numWorkers);
var splitKey = brokenKey.split("?");
var iteratorStart = Number(startIter) || Math.pow(58, (splitKey.length - 2));
var duration = Math.pow(58, (splitKey.length - 1));
var workers = [];
var latestStatus = null, latestUpdate = 0;
var statusUpdate = function (info) {
if (!latestStatus || info[0] > latestStatus[0]) {
latestStatus = info;
if (!latestUpdate || (info[0] - latestUpdate) >= updateFrequency) {
console.info(`Current Status ${info}`);
latestUpdate = info[0];
}
}
};
let solved = false;
for (let w = 0; w < numWorkers; w++) {
workers.push(new Promise((resolve, reject) => {
var workerLoop = function (i) {
var possibleKeyParts = encode(i).split("");
var newKey = splitKey.map(function (keyPart, index) {
if (!possibleKeyParts[index]) {
possibleKeyParts[index] = "";
}
return keyPart + possibleKeyParts[index];
});
var joinedKey = newKey.join('');
if (base58check(joinedKey)) {
console.log("Private key found: " + joinedKey);
console.log("Used: " + encode(i));
return { value: joinedKey };
}
if (i % updateFrequency === 0) {
statusUpdate([i, i / duration, encode(i), joinedKey]);
}
};
for (var i = (iteratorStart + w); i < duration; i += numWorkers) {
if (!!solved) break;
var workerState = workerLoop(i);
if (typeof workerState === "object") {
return resolve(workerState.value);
}
}
}).catch(e => console.error(`Worker ${w} has failed. [${e}]`))
);
}
let result = await Promise.race(workers).then((result) => {
console.info(`Found Key: ${result}`);
});
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment