entropy (355B)
1 #!/bin/sh 2 # entropy: calculate the entropy of a password given it's length and number of 3 # possible characters 4 set -e 5 num=0 6 [ "$1" = '-n' ] && { num=1; shift; } 7 [ "$#" -ne 2 ] && { echo "usage: ${0##*/} [-n] possibilites length " 1>&2; exit 1; } 8 echo "l($1^$2)/l(2)" | bc -l | xargs printf "%.2f" 9 [ "$num" -eq 0 ] && printf " bits of entropy" 10 printf "\n"