diceware

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 7 Imported by: 6

README

diceware

Simple golang library that allows for quick generation of diceware passphrases.

PkgGoDev Go Report Card test golangci-lint

Background Information

Installation

go get -u github.com/everlastingbeta/diceware

Example

package main

import (
  "fmt"

  "github.com/everlastingbeta/diceware"
  "github.com/everlastingbeta/diceware/wordlist"
)

func main() {
  // generate diceware passphrase of 8 words with a separator of "-" using the
  // EFF Long wordlist.
  effLongPassphrase, err := diceware.RollWords(8, "-", wordlist.EFFLong)
  if err != nil {
    panic(err)
  }

  fmt.Println("EFF Long wordlist passphrase: ", effLongPassphrase)

  // generate diceware passphrase of 8 words with a separator of "-" using the
  // EFF Long wordlist, with enhanced entropy.
  effLongPassphrase, err = diceware.RollWords(8, "+", wordlist.EFFLong, true)
  if err != nil {
    panic(err)
  }

  fmt.Println("EFF Long wordlist passphrase with enhanced entropy: ", effLongPassphrase)

  // generate diceware passphrase of 8 words with a separator of "-" using the
  // EFF short wordlist.
  effShortPassphrase, err := diceware.RollWords(8, "-", wordlist.EFFShort)
  if err != nil {
    panic(err)
  }

  fmt.Println("EFF Short wordlist passphrase: ", effShortPassphrase)

  // generate diceware passphrase of 8 words with a separator of "-" using the
  // EFF ShortPrefix wordlist.
  effShortPrefixPassphrase, err := diceware.RollWords(8, "-", wordlist.EFFShortPrefix)
  if err != nil {
    panic(err)
  }

  fmt.Println("EFF ShortPrefix wordlist passphrase: ", effShortPrefixPassphrase)

  // generate diceware passphrase of 8 words with a separator of "-" using the
  // Original wordlist.
  originalPassphrase, err := diceware.RollWords(8, "-", wordlist.Original)
  if err != nil {
    panic(err)
  }

  fmt.Println("Original wordlist passphrase: ", originalPassphrase)
}

Sample Output
EFF Long wordlist passphrase:  playlist-wisplike-chive-coaster-caution-hypnoses-reliable-mangy
EFF Long wordlist passphrase with enhanced entropy:  c:onsult+ma9roon+sizzl3e+sm-ugly+usea?ble+supermom+delusion+cozily
EFF Short wordlist passphrase:  churn-wish-july-aroma-agile-curry-stain-boxer
EFF ShortPrefix wordlist passphrase:  ghoulishly-henceforth-dresser-announcer-gumdrop-riskily-mudflow-exfoliate
Original wordlist passphrase:  bunny-count-cloy-trust-mw-mere-queasy-egg

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidWordlist represents the error given when `RollWords` is called
	// with a nil wordlist
	ErrInvalidWordlist = errors.New("invalid nil wordlist given")
	// ErrInvalidWordFetched represents the error given when a word is not
	// returned from the internal wordlist's `FetchWord` method is called
	ErrInvalidWordFetched = errors.New("invalid empty word fetched")
)

Functions

func RollWords

func RollWords(wordCount int, separator string, wl Wordlist, enhanceEntropy ...bool) (string, error)

RollWords returns a string. Implements the logic required to pull several words without needing to create. wordCount is the number of words that should be returned. separator is the character(s) used to separate each of the passphrase words. wl is the implementation of the `diceware.Wordlist` that will be utilized in order to fetch the words for the final passphrase. enhanceEntropy is the [optional] boolean required to add a random character or number within the passphrase. At minimum 1 word within the requested passphrase will be modified. If no enhanceEntropy value is passed in, then it will default to false.

Types

type Wordlist

type Wordlist interface {
	// FetchWord describes the logic to fetch a word from the word list with the
	// given dice roll value
	FetchWord(int) string

	// Rolls describes the number of dice that should be rolled to retrieve an
	// appropriate word from the wordlist
	Rolls() int

	// SidesOfDice describes the maximum number on the dice to be rolled
	SidesOfDice() *big.Int
}

Wordlist defines the methods required to implement a list of words that can be utilized within the diceware implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL