Skip to content

Instantly share code, notes, and snippets.

@CQBinh
Created May 22, 2019 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CQBinh/55784561007bf873366427be6e132732 to your computer and use it in GitHub Desktop.
Save CQBinh/55784561007bf873366427be6e132732 to your computer and use it in GitHub Desktop.
The snip code to recover ethereum private key when we know the address and some-chars-missed-private-key
const util require('util')
const eUtil = require('ethereumjs-util')
function translate(str = '', list = []) {
for (const i of list) {
str = util.format(str, i)
}
return str
}
function decrypt(key, address) {
const chars = ['A', 'B', 'C', 'D', 'E', 'F', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
chars.forEach(item1 => {
chars.forEach(item2 => {
chars.forEach(item3 => {
chars.forEach(item4 => {
const candidate = translate(key, [item1, item2, item3, item4])
const account = eUtil.privateToAddress(new Buffer(candidate, 'hex'))
if (account.toString('hex').toLowerCase() === address.toLowerCase()) {
console.log('key', candidate)
}
})
})
})
})
}
decrypt('6E90D8%s3A057%s20299EA6F342A75869F3E751CA1F6EEE255B4A7%s17%s6DDF0BF2', '7ea379e0777c04310679cd9670d03d2607418091')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment