G1Pola/diceware.sh

18 lines
539 B
Bash

#!/usr/bin/env bash
# Default to 6 word passphrase
MOTS=$(echo "$1" | grep -E "^\-?[0-9]+$")
if [[ "$MOTS" == "" ]]; then MOTS=4; fi
WORDCOUNT=${1-$MOTS}
# Download the wordlist
# wget -nc -O ~/.diceware-wordlist http://world.std.com/%7Ereinhold/diceware.wordlist.asc 2> /dev/null
# print a list of the diceware words
cat ./diceware-wordlist.txt |
awk '/[1-6][1-6][1-6][1-6][1-6]/{ print $2 }' |
# randomize the list order
shuf --random-source=/dev/urandom |
# pick the first n words
head -n ${WORDCOUNT} |
# pretty print
tr '\n' ' '
echo