Skip to content

Instantly share code, notes, and snippets.

@mrunyon
Forked from l0s/gen-xkcd-pass
Last active April 6, 2017 17:44
Show Gist options
  • Select an option

  • Save mrunyon/a5cdb363d791008b631f to your computer and use it in GitHub Desktop.

Select an option

Save mrunyon/a5cdb363d791008b631f to your computer and use it in GitHub Desktop.
XKCD password generator for BSD / Mac OS X
# adapted from: https://pthree.org/2015/09/05/password-generation-in-the-shell/
# which is inspired by: https://xkcd.com/936/
# Modified to use a list of 10,000 most common English words.
# Outputs exactly 4 words, separated by a dash
gen-xkcd-pass() {
[ $(echo "$1"|grep -E "[0-9]+") ] && NUM="$1" || NUM=1
DICT=$(LC_CTYPE=C grep -E "^[a-zA-Z]{3,6}$" /Users/mrunyon/words-common.txt)
for I in $(seq 1 "$NUM"); do
WORDS=$(echo "$DICT"|gshuf -n 4|paste -sd ' ' -)
XKCD=$(echo "$WORDS"|sed 's/ /-/g')
echo "$XKCD ($WORDS)"|awk '{x=$1;$1="";printf "%-36s %s\n", x, $0}'
done | column
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment