summaryrefslogtreecommitdiffstats
path: root/diceware.go
blob: 26e59aabaef32a9e1b45a207684e515c46007486 (plain) (blame)
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
// Copyright 2026 Rose Hogenson <r@roseh.moe>
//
// This file is part of diceware.
//
// Diceware is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// Diceware is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// diceware. If not, see <https://www.gnu.org/licenses/>.

package main

import (
	"crypto/rand"
	"encoding/binary"
	"flag"
	"fmt"
	"os"
	"strings"

	"roseh.moe/pkg/wordlist"
)

var n = flag.Int("n", 10, "number of words to generate")

func main() {
	flag.Parse()
	if *n < 0 {
		fmt.Fprintln(os.Stderr, "What are you doing...")
		os.Exit(2)
	}
	buf := make([]byte, 2**n)
	rand.Read(buf)
	words := make([]string, *n)
	for i := range words {
		words[i] = wordlist.Words[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]
	}
	fmt.Println(strings.Join(words, " "))
}