summaryrefslogtreecommitdiffhomepage
path: root/Entropy.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-07 12:09:53 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-07 12:09:53 -0400
commit6205bbac7abc919371a5e7af9e4ba1a8d70de85e (patch)
tree668f3247182d01f025ce9122f6b495def240eb71 /Entropy.hs
parent016877aa55764d14af3c16645d64fd95bf6a2da1 (diff)
downloadkeysafe-6205bbac7abc919371a5e7af9e4ba1a8d70de85e.tar.gz
basic password entropy calculation
Diffstat (limited to 'Entropy.hs')
-rw-r--r--Entropy.hs9
1 files changed, 9 insertions, 0 deletions
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