Last active
October 13, 2020 17:04
-
-
Save meznak/f230e36d7d8f8cbbf62a9a80a9eff0d7 to your computer and use it in GitHub Desktop.
CLI passphrase generator
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
#!/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