#! /usr/bin/bash # # This work is in the public domain. # # It was completed by Arun I in 2016. # # Though you are not legally obliged to do so, I would appreciate it # if you credit me for this work by not removing this notice, and # hopefully linking to my blog post at # https://systemreboot.net/post/simple-passphrase-generator-in-bash WORDLIST=~/eff_large_wordlist.txt NO_OF_WORDS=6 function random-line { NO_OF_LINES=$1 RANDOM_NO=$(od -An -N 2 -t u2 < /dev/random) if [[ $RANDOM_NO -lt $NO_OF_LINES ]] then echo $(expr $RANDOM_NO + 1) else random-line $NO_OF_LINES fi } NO_OF_LINES=$(wc -l < $WORDLIST) for i in $(seq 1 $NO_OF_WORDS) do RANDOM_LINE=$(random-line $NO_OF_LINES) RANDOM_WORD=$(sed -n ${RANDOM_LINE}p $WORDLIST | awk '{print $2}') printf "%s " $RANDOM_WORD done printf "\n"