Skip to content

Commit

Permalink
add file parameter for using an external word list
Browse files Browse the repository at this point in the history
  • Loading branch information
shibumi committed Jun 1, 2020
1 parent 6bb27ca commit 282ab44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
* specify number of words
* different languages: English, German
* specify a delimeter between words
* use an external file as word list

## how to use it

```
Usage of ./mnemonic:
-d string
delimeter as split element for the password (default "-")
-f string
path to external word list
-l string
language of word list: [en, de] (default "en")
-n uint
Expand Down Expand Up @@ -56,5 +59,4 @@ This should drop a binary in the project directory named `mnemonic`.
* provide a `-m`, `--max` parameter for setting a characterlimit. Useful for websites with password character limit.
* tests, tests.. tests
* build release binaries magically via github actions
* specify your own word list via `-f`, `--file` parameter
* option for generating random numbers as padding/delimeter
34 changes: 22 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"math/rand"
"time"
)

func newWordList(language string) (list []string, err error) {
var assetFile string
switch language {
case "de":
assetFile = "lists/frequency.txt"
default:
assetFile = "lists/tothink.txt"
func newWordList(language string, file string) (list []string, err error) {
var asset []byte
if file == "" {
var assetFile string
switch language {
case "de":
assetFile = "lists/frequency.txt"
default:
assetFile = "lists/tothink.txt"
}
asset, err = Asset(assetFile)
if err != nil {
return nil, err
}
} else {
asset, err = ioutil.ReadFile(file)
if err != nil {
return nil, err
}
}

asset, err := Asset(assetFile)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(bytes.NewReader(asset))
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
Expand All @@ -49,9 +58,10 @@ func main() {
numberOfWords := flag.Uint("n", 3, "number of words")
delimeter := flag.String("d", "-", "delimeter as split element for the password")
language := flag.String("l", "en", "language of word list: [en, de]")
file := flag.String("f", "", "path to external word list")
flag.Parse()

list, err := newWordList(*language)
list, err := newWordList(*language, *file)
if err != nil {
log.Fatalln(err)
}
Expand Down

0 comments on commit 282ab44

Please sign in to comment.