alea 0.3.1.0 → 0.3.2.0
raw patch · 6 files changed
+58/−9 lines, 6 files
Files
- Alea/Diceware.hs +28/−0
- Alea/List.hs +10/−0
- Alea/Random.hs +6/−0
- Main.hs +7/−6
- README.md +1/−1
- alea.cabal +6/−2
+ Alea/Diceware.hs view
@@ -0,0 +1,28 @@+module Alea.Diceware where++import Data.List (intersect, elemIndex)+import Alea.List++-- Diceware dictionary type+type Diceware = [String]++-- Parse file content to a Diceware+parseDiceware :: String -> Diceware+parseDiceware x = map (last . split ' ') $ lines x++-- Lookup word with dice index+readDiceware :: Diceware -> Int -> String+readDiceware d n = show n ++ " -> " +++ case (undice n) of+ Just x -> d !! x+ Nothing -> "Does not exist"++-- Lookup word with linear index+readDiceware' :: Diceware -> Int -> String+readDiceware' d n = d !! n++-- Dice numbers to numbers+-- Ex. undice 11121 == Just 6+undice :: Int -> Maybe Int+undice n = elemIndex n . filter+ (null . (intersect "0789") . show) $ [11111..66666]
+ Alea/List.hs view
@@ -0,0 +1,10 @@+module Alea.List where++-- Split a list into a list of lists+-- ex. split ',' "ab,cd,ef" == ["ab","cd","ef"]+split :: (Eq a) => a -> [a] -> [[a]]+split _ [] = [[]]+split delim (c:cs)+ | c == delim = [] : rest+ | otherwise = (c : head rest) : tail rest+ where rest = split delim cs
+ Alea/Random.hs view
@@ -0,0 +1,6 @@+module Alea.Random where++import Crypto.Threefish.Random++randWords :: Int -> Int -> IO [Int]+randWords n k = newSkeinGen >>= return . take k . randomRs (0, n-1)
Main.hs view
@@ -17,14 +17,15 @@ } deriving (Show) parser :: IO (ParserSpec ProgArgs)-parser = path >>= \path -> return $ ProgArgs+parser = (\path -> ProgArgs `parsedBy` boolFlag "interactive" `Descr` "Manually insert numbers" `andBy` optFlag path "dictionary" `Descr` "Specify dictionary file path" `andBy` optFlag 6 "lenght" `Descr` "Number of words in a passphrase"- `andBy` optFlag 1 "phrases" `Descr` "Number of passphrases to generate"+ `andBy` optFlag 1 "phrases" `Descr` "Number of passphrases to generate")+ <$> path interface :: IO (CmdLnInterface ProgArgs)-interface = +interface = (`setAppDescr` "A diceware passphrase generator") <$> (`setAppEpilog` "Alea iacta est.") <$> (mkApp =<< parser)@@ -39,7 +40,7 @@ -- Read dictionary file readDict :: ProgArgs -> IO ProgArgs readDict args@ProgArgs{..} =- readFile dictionary >>= \x -> return args {dictionary = x}+ (\x -> args {dictionary = x}) <$> readFile dictionary -- Main function exec :: ProgArgs -> IO ()@@ -47,8 +48,8 @@ if interactive then interact (unlines . map dice . lines) else do- randWords dictSize phraseLength >>= putStrLn . unwords . map dice'- when (phrases > 1) $ exec args {phrases = phrases - 1}+ randWords dictSize phraseLength >>= putStrLn . unwords . map dice'+ when (phrases > 1) $ exec args {phrases = phrases - 1} where (dict, dictSize) = (parseDiceware dictionary, length dict) dice n = readDiceware dict (read n :: Int)
README.md view
@@ -15,7 +15,7 @@ $ alea doso epurai usci selve dirupo bs - $ alea --phrases 3 --phraselength 8+ $ alea -p 3 -l 8 sturai sapone ripeto leghi osasse fori terme oserai carta getto osiamo banale figura smilzi celibe gigli porvi rs traini dotati aureo solito malato gelate
alea.cabal view
@@ -1,5 +1,5 @@ name: alea-version: 0.3.1.0+version: 0.3.2.0 synopsis: a diceware passphrase generator description: @@ -19,10 +19,14 @@ data-files: dict/diceware cabal-version: >=1.10 +source-repository head+ type: git+ location: https://github.com/rnhmjoj/alea+ executable alea main-is: Main.hs default-language: Haskell2010- other-modules: Paths_alea+ other-modules: Alea.Diceware, Alea.List, Alea.Random, Paths_alea other-extensions: DeriveDataTypeable, RecordWildCards build-depends: base ==4.7.* , containers ==0.5.*, argparser ==0.3.*, threefish == 0.2.*