Skip to content

Instantly share code, notes, and snippets.

@reinhrst
Last active April 21, 2023 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinhrst/7a86606485fa2955369def8585f12bb3 to your computer and use it in GitHub Desktop.
Save reinhrst/7a86606485fa2955369def8585f12bb3 to your computer and use it in GitHub Desktop.
Correct horse battery staple: creates a password of english words. First param is number of words to use (default=3)
TEMPDIR="$(mktemp -d)"
NR_WORDS=${1:-3}
cd "$TEMPDIR"
curl 'https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt' | grep -E "^.{4,8}$" | sort | uniq > wordlist.txt
NR_LINES="$(wc -l wordlist.txt | grep -oe '\d\+')"
POSS="$(echo "$NR_LINES^$NR_WORDS" | bc)"
BITS="$(echo "l($POSS)/l(2)" | bc -l)"
CHARS="$(echo "l($POSS)/l(72)" | bc -l)"
printf 'We have %d lines; we willl take %d words; there are %.3e possibilities (%.1f bits of entropy, comparable to %.1f completely random chars (lower/upper/number/special))\n' "$NR_LINES" "$NR_WORDS" "$POSS" "$BITS" "$CHARS"
if [[ $NR_LINES -lt "4000" ]]; then
echo "WARNING: LIST OF WORDS IS TOO SMALL; continue at own risk"
fi
cat wordlist.txt | shuf -n $NR_WORDS | tr '\n' - | rev | cut -c 2- | rev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment