From 6205bbac7abc919371a5e7af9e4ba1a8d70de85e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 7 Aug 2016 12:09:53 -0400 Subject: basic password entropy calculation --- Entropy.hs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Entropy.hs (limited to 'Entropy.hs') diff --git a/Entropy.hs b/Entropy.hs new file mode 100644 index 0000000..2ff28b2 --- /dev/null +++ b/Entropy.hs @@ -0,0 +1,9 @@ +module Entropy where + +import Data.List + +entropy :: String -> Double +entropy = sum . map lg' . fq' . map (fromIntegral.length) . group . sort + where + lg' c = (c * ) . logBase 2 $ 1.0 / c + fq' c = let sc = sum c in map (/ sc) c -- cgit v1.2.3