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