public
Created

This is a way to generate a user-defined diceware passphrase list, instead of the one found at http://world.std.com/~reinhold/diceware.html. Only currently supports 5 dice. Tested on Ubuntu 12.04.

  • Download Gist
GenerateDiceware.sh
Shell
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#!/bin/bash
 
DICTFN="/usr/share/dict/words"
NUMBERZ="1 2 3 4 5 6"
NUMDICE=5
WORDLIST=""
DICEARRAY=""
 
# TODO allow dynamic number of dice (up to a point, max size of dictfile)
 
# This is a way to generate a user-defined diceware passphrase list, instead of
# the one found at http://world.std.com/~reinhold/diceware.html
 
function printUsage()
{
echo "Usage: $0 -f dictionaryToRead -d numberOfDice"
}
 
while getopts “f:d:h” OPTION
do
case $OPTION in
f)
DICTFN=$OPTARG
;;
d)
NUMDICE=5
# NUMDICE=$OPTARG
# Not being applied ATM, logic isn't in place for this to work
;;
h)
printUsage
exit 1
;;
*)
printUsage
exit 127
;;
esac
done
 
NUMTOPULL=$(echo "6 ^ $NUMDICE" | bc)
 
if [ -f $DICTFN ]
then
export WORDLIST=$(cat $DICTFN | sort -R | head -n $NUMTOPULL | tr '[A-Z]' '[a-z]')
else
echo "Not a valid file"
fi
 
WORDARRAY=($WORDLIST)
WORDARRAYLN=${#WORDARRAY[@]}
 
if [ $WORDARRAYLN -lt $NUMTOPULL ]
then
echo "$DICTFN is only $WORDARRAYLN lines long, need at least $NUMTOPULL lines."
exit 1
fi
 
for number0 in $(echo $NUMBERZ); do
for number1 in $(echo $NUMBERZ); do
for number2 in $(echo $NUMBERZ); do
for number3 in $(echo $NUMBERZ); do
for number4 in $(echo $NUMBERZ); do
DICELIST+=$(echo -n "${number0}${number1}${number2}${number3}${number4} ") ;
done
done
done
done
done
 
DICEARRAY=($DICELIST)
 
for (( i = 0 ; i < $NUMTOPULL ; i++ ))
do
echo "${DICEARRAY[$i]} ${WORDARRAY[$i]}"
done
 
exit 0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.