Skip to content

Instantly share code, notes, and snippets.

@meznak
Last active Oct 13, 2020
Embed
What would you like to do?
CLI passphrase generator
#!/usr/bin/env bash
#####
# Passphrase generator a la Diceware and XKCD
#
# Usage:
# chbs.sh [word count] [phrase count]
#
# https://gist.github.com/meznak/f230e36d7d8f8cbbf62a9a80a9eff0d7
# https://xkcd.com/936/
# https://theworld.com/~reinhold/diceware.html
#
# CC BY SA 2020 Nate Plamondon
#####
dict_file=~/eff_large_wordlist.txt
[[ -f $dict_file ]] || `wget https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt -o dict_file`
dict_count=`wc -l ${dict_file} | cut -d\ -f5`
word_count=5
pass_count=5
pass=""
[[ $1 != "" ]] && word_count=$1
[[ $2 != "" ]] && pass_count=$2
n=0
while [[ $n -lt $pass_count ]]; do
pass=""
i=0
while [[ $i -lt $word_count ]]; do
rand=`od -vAn -N4 -tu4 < /dev/urandom`
let "line = $rand % dict_count"
word=`sed -n "${line}p" ${dict_file} | awk '{ print $2 }'`
#echo "$line $word"
pass+="${word} "
let "i++"
done
let "length = ${#pass} - 1"
echo "$length - $pass"
let "n++"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment