-
Notifications
You must be signed in to change notification settings - Fork 3
/
bip39checksum.go
47 lines (38 loc) · 881 Bytes
/
bip39checksum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bufio"
"fmt"
"github.com/tyler-smith/go-bip39"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Please enter 11 or 23 BIP39 words: ")
input, _ := reader.ReadString('\n')
words := brute(input)
mnemonicLen := len(words)
if mnemonicLen > 0 {
fmt.Printf("\nThere are %v last words valid for this mnemonic: \n\n", mnemonicLen)
printWords(words)
} else {
fmt.Println("The mnemonic phrase you entered is not valid.")
}
}
func brute(mnemonic string) []string {
english := bip39.GetWordList()
var valid_words []string
for _, word := range english {
current := mnemonic + " " + word
isValid := bip39.IsMnemonicValid(current)
if isValid {
valid_words = append(valid_words, word)
}
}
return valid_words
}
func printWords(arr []string) {
for _, w := range arr {
fmt.Printf("- %s\n", w)
}
fmt.Println()
}