Skip to content

Instantly share code, notes, and snippets.

@tayvano
Last active January 5, 2024 00:33
Show Gist options
  • Save tayvano/7755e3e8d8b64581d5ff2865087b93f8 to your computer and use it in GitHub Desktop.
Save tayvano/7755e3e8d8b64581d5ff2865087b93f8 to your computer and use it in GitHub Desktop.
const util = require('ethereumjs-util')
const Wallet = require('ethereumjs-wallet')
var possible = 'abcdef1234567890'
var basePrivateKey = '1cd3b30424316919712c48359829787eefa0d724a78274a506530dbb72'
var charsMissing = 64 - basePrivateKey.length
var targetPublicAddress = ' 0xe8Ca70C909905Ebbbe6a49c34797beF31d895241'
var missingPart = '';
for (var i = 0; i < charsMissing; i++) {
missingPart = missingPart.concat('f');
}
var maxVal = parseInt(missingPart, 16);
console.log(" \n " +
"searching for address : " + targetPublicAddress + " \n " +
"base private key : " + basePrivateKey + " \n " +
"missing chars : " + charsMissing + " \n " +
"it will be quiet now. if you don't see anything below me, it's working on finding your key." + " \n " +
"If you see something below that doesn't say 'FOUND KEY!', you have an error" + " \n " )
function makeHexString(numb) {
var hex = numb.toString(16);
for (var i = 0; i < charsMissing - hex.length; i++)
hex = '0' + hex
return hex
}
for(var i = 0; i <= maxVal; i++){
try{
var endPrivateKey = makeHexString(i)
var privateKeyGuess = basePrivateKey + endPrivateKey
var wallet = Wallet.fromPrivateKey(new Buffer(privateKeyGuess, "hex"))
var publicAddress = util.bufferToHex(wallet.getAddress())
// console.log(i + ": " + endPrivateKey)
if(publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()){
console.log('\n \n \n \n ********************************** FOUND PRIVATE KEY: ' + privateKeyGuess + " \n matching address " + targetPublicAddress + " \n \n \n \n ");
process.exit();
}
}catch(e){
null;
}
if (i % 100000 === 0) {
console.log('checked', i, 'keys');
}
}
/*
Credit goes to Bahk (https://github.com/domalak) for making the best helper tools ever!
How to Use (for noobs)
- Click "Raw" on https://gist.github.com/tayvano/7755e3e8d8b64581d5ff2865087b93f8
- Right click, select "Save As"
- Click "Save"
- Install Node.js: https://nodejs.org/en/
- Open the .js file you saved earlier in a text editor (NOT WORD!!!!!!!!!!) like Notepad (PC) or Text Edit (Mac)
- Change the stuff between the ' ' characters to the characters you have of your private key. Check it 5 times to be sure you got the correct characters in there:
var basePrivateKey = 'afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b15781404'
- Change the stuff between the ' ' characters to your address:
var targetPublicAddress = '0x06A85356DCb5b307096726FB86A78c59D38e08ee';
- Open command line / terminal
- Type "cd" into the command line (w/o quotes: just cd) and then hit the spacebar and then drag and drop the FOLDER that contains the .js file into command line window
- It should look like /Users/tayvano/Downloads/7755e3e8d8b64581d5ff2865087b93f8-653a14e63b9ccefb5a8ddfdb14bd7066b4fd4c6f (or something like that).
- Hit enter.
- Copy & paste the following into command line and hit enter:
npm install ethereumjs-wallet ethereumjs-util
- Wait until it installs
- Type "node" into the command line (w/o quotes: just cd) and then hit the spacebar and then drag and drop the brute_force_end_of_private_key.js FILE into the command line window
- Hit enter.
You should see the following:
$ node /Users/tay/Desktop/brute_force_8_char.js
searching for address : 0x06A85356DCb5b307096726FB86A78c59D38e08ee
base private key : afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b15781404
missing chars : 8
it will be quiet now. if you don't see anything below me, it's working on finding your key.
If you see something below that doesn't say 'FOUND KEY!', you have an error
When it's done it will show:
********************************** FOUND PRIVATE KEY: afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890
matching address 0x06A85356DCb5b307096726FB86A78c59D38e08ee
If you see anything besides that, you have an error and it's not longer searching for your key.
If the error says, "Invalid private key", the key snippet your provided is invalid. It must be hex characters.
If you get an "out of memory" error, have to go to work, or your computer turns off, no worries. Just run it again.
If your command line is still open, hit the up arrow key and then enter to quickly run it again.
On a macbook pro, it will take seconds to find 1, 2, 3, or 4 missing characters.
It takes ~15mins to find 6 digits.
It will ~3 days to find 8
*/
@invisideath
Copy link

invisideath commented Feb 16, 2018

hoping this will work out for me... currently working on errors when executing "npm install ethereumjs-wallet ethereumjs-util" from this tutorial https://myetherwallet.github.io/knowledge-base/private-keys-passwords/missing-characters-of-private-key.html

so far i got a "directory names are too long" error, and currently getting "Failed to locate CL.exe"

GOT IT! here is how i did it https://www.reddit.com/r/MyEtherWallet/comments/7y1xxf/private_key_missing_4_characters_when_issued/

https://archive.fo/yUIDP

thanks so much! how can i repay you?

Copy link

ghost commented May 12, 2018

I'm trying to restore a private key from a Bitcoin wallet, would that algorithm work? I have only 47 characters of the private key that is made up of 51.

@robimage
Copy link

You can send mail to keychainx@protonmail.com and get help to bruteforce crack the key. We have helped others.

@GreenAsGrass
Copy link

Hi thank you so much for coming up with the code for this program, im sure it has helped a lot of people! However I appear to be having some issue using it. Am missing 3 characters from my ethereum private key, so it shouldn't take very long for this code to work.

May I send you a screenshot of the issue in my commandprompt?

@GreenAsGrass
Copy link

I'm quite new to using javascript and running command prompts.would really appreciate any help thanks so much! Been trying for half a day already haha

@GreenAsGrass
Copy link

image

This is the issue I am having at the moment. Please any help is greatly appreciated :)

@GreenAsGrass
Copy link

That issue disappeared after I replaced all "Buffer" with "Buffer.alloc". However, still does not worked. After checked 0 keys, it stops. This is what it looks like (using an ethereum wallet with no value)

image

@SteliosIoannou
Copy link

The script assumes that the missing characters are at the end of the string. For me this wasn't the case I forgot to write a digit for my private key in the middle of the text, so I modified the script to match my needs.

Here is the modification that I made if anyone wants to use it.

image

`for(var i = 0; i = maxVal; i++){
try{
for(var j =0; j = basePrivateKey.length ; j++){
var endPrivateKey = makeHexString(i)
var privateKeyGuess = basePrivateKey.substring(0,j) + endPrivateKey + basePrivateKey.substring(j,basePrivateKey.length)
var wallet = Wallet.fromPrivateKey(new Buffer(privateKeyGuess, hex))
var publicAddress = util.bufferToHex(wallet.getAddress())

if(publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()){
  console.log('Found Private Key: ' + privateKeyGuess +  n n n n );
  process.exit();
}

}
}catch(e){
console.log(e);
}
}
`

@SkAlauddin66
Copy link

Myetherwallet password keystore files my address 0xf0a29AB8A50F9bA8bAC94343Bc225cbD59D493a5

@SkAlauddin66
Copy link

Myetherwallet problem my private key address 0xf0a29AB8A50F9bA8bAC94343Bc225cbD59D493a5

@VadimIsk
Copy link

Myetherwallet problem my private key address 0x419dcD03Daa3C69060A71fAc72481cDFFC3d73eA
vadimplus@list.ru

@Outkax
Copy link

Outkax commented Dec 13, 2018

How long will it take for 14 characters ?

@bITCOIN555
Copy link

Hi I lost private key

@ripelchakma
Copy link

please sir help me. myetherwallet problem my private key address 0xFe7061D21Ed15ce7c61793cFaC3A74fB65727546

@amd1361
Copy link

amd1361 commented Feb 22, 2019

Hi there
I have printed my etc public and private keys but unfortunately the last 8 letters of my private keys have not been printed
Who can help to restore it using the above mentioned method ?
please help
amd1361@gmail.com

@Mfomo
Copy link

Mfomo commented Mar 24, 2019

Please I mistakenly deleted two digits from my private key I need one to kindly help me out or recommend one that’s trustworthy..

@MAITHI19
Copy link

is this script work with bitcoin core wallet.dat hex

@crispy-coffee
Copy link

The script assumes that the missing characters are at the end of the string. For me this wasn't the case I forgot to write a digit for my private key in the middle of the text, so I modified the script to match my needs.

Here is the modification that I made if anyone wants to use it.

image

`for(var i = 0; i = maxVal; i++){ try{ for(var j =0; j = basePrivateKey.length ; j++){ var endPrivateKey = makeHexString(i) var privateKeyGuess = basePrivateKey.substring(0,j) + endPrivateKey + basePrivateKey.substring(j,basePrivateKey.length) var wallet = Wallet.fromPrivateKey(new Buffer(privateKeyGuess, hex)) var publicAddress = util.bufferToHex(wallet.getAddress())

if(publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()){
  console.log('Found Private Key: ' + privateKeyGuess +  n n n n );
  process.exit();
}

} }catch(e){ console.log(e); } } `

Hey, I have the same problem as yours. I have lost the char from my key in between, but the part of your code throws an error continuously, can you please check it and make it work perfectly?

@spartacus2690
Copy link

سلام اقا تورا قسم به هرکسی که میپرستی زندگی من نابود داره میشه کلید گم کردم وتاز
ه کارهستم

@spartacus2690
Copy link

سلام اقا تورا قسم به هرکسی که میپرستی زندگی من نابود میشه میشه کلید گم کردم وتاز ه کارهستم

@ayah1525
Copy link

Hi I lost private key

i can help, but the cost is 40% from your balance.

@VadimIsk
Copy link

VadimIsk commented Sep 1, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment