Before approximately 2 days my ledger was reset. So naturally I took out the seed and typed it out on my ledger and it kept saying invalid phrase I tried the same on hot wallets , same thing
Then I realised that maybe its something that I’m doing isn’t right so I started reading upon mnemonics and how they’re generated
A **mnemonic sentence** (“mnemonic code”, “seed phrase”, “seed words”) is a way of representing a large randomly-generated *number* as a sequence of [words](https://learnmeabitcoin.com/technical/mnemonic#bip39-wordlist), making it easier for humans to store.
For the creation of a mnemonic phrase, we need at least 128 bits of entropy, and at most 256 bits. Depending on the length of the initial entropy, the mnemonic phrase will be 12 to 24 words long.
Let’s say we want to create a 24-word-long mnemonic phrase. We start off by generating 256 bits of entropy.
This is an example of 256 bits of entropy
We then take the first entropy length / 32 bits of the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) hash of the entropy. So, in our case, we take 264 / 32 = 8 bits, which results in 11000100.
This is the *checksum* for our mnemonic phrase. Then, we append the checksum to the entropy, resulting in bits (264 bits of entropy and 8 bits of the checksum). We split the 264 bits into groups of 11 bits, which looks like this:
`00010010111 11111100100 11010011101 00000011110 10100001010 10001001100 01100011010 11000001001 10011010011 01110101000 00101000101 00010010110 01010001000 11111101101 01101101010 10001001010 10100110100 10110010110 01100111101 00001110011 10000000100 01010000001 11001101000 01011000100`
This is the binary form of words ranging from 0-2047 ( we have 2048 words in english.txt) which directly translates to the seed
`base wish squirrel adult pattern maze globe scorpion omit insect chunk barrel extra world hood matter pledge ready guilt attack letter expand snack flat`
These are the basics of mnemonics
Now to the part where you can “recover” your seed considering you have all of your words and one or two went wrong while noting them down ( If you see my previous posts you’ll know I lost mine hence made this program to recover)
There’s two possibilities in where you got one word wrong
1) Last word (or checksum) is wrong
2) One of the first 23 words are wrong
For the first case it’s really easy to recover just Enter your 24 words in the mnemonic box in [this website](https://learnmeabitcoin.com/technical/mnemonic)
[ Warning do not enter your seeds on any websites unless they’re absolutely trusted]
Just copy and paste the same entropy and you’ll get the right mnemonic , Try to recover using that if it doesn’t work its second case
Considers checksum (or last word) is right
It takes all the words closest to the seed words using the [Levenstein’s distance](https://en.wikipedia.org/wiki/Levenshtein_distance) and tries all possible conditions where only one word is wrong and gets the seed
Example : The 24 words I’m using here as example are `lift cricket must assist repair dose damp acid notice blade regular mobile pudding rival process hazard anchor meat water current gorilla multiply cruel wrist`
I’ll be intentionally changing the third word `must` to `music`
Now using the program , Ill be running it generates the files `seeds, log.log, allnumbers` where seeds contains all the possible combinations and allnumbers contains the binary form of seeds and lastly log.log which if successfully finds the seed stores it in the end of the file
With this I end my write up with the links
Source code for recovery : [https://github.com/sonuishaq67/recover-ledger-seed](https://github.com/sonuishaq67/recover-ledger-seed)
Sources for write up on mnemonics :
View Reddit by sonuishaq67 – View Source