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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment