1 module Main(main) where
3 import Data.Hash.MD5 (md5s, Str(..))
4 import Data.List (isPrefixOf)
5 import qualified Data.Map.Lazy as Map
7 type Password = Map.Map Integer Char
19 putStrLn $ take 8 [h!!5 | h <- filter (interesting) $ md5sequence input 0]
23 putStrLn $ Map.foldr (:) [] password
24 where interestingHashes =
25 [(read [h!!5], h!!6) |
26 h <- filter (interesting) (md5sequence input 0),
27 h!!5 `elem` "01234567"]
28 password = findPassword Map.empty interestingHashes
31 md5sequence :: String -> Integer -> [String]
32 md5sequence key i = (md5s (Str (key ++ show i))) : (md5sequence key (i+1))
34 interesting :: String -> Bool
35 interesting hash = "00000" `isPrefixOf` hash
37 dontReplace :: (Integer, Char) -> Password -> Password
38 dontReplace (k, v) = Map.insertWith (\_ v -> v) k v
40 findPassword :: Password -> [(Integer, Char)] -> Password
43 | otherwise = findPassword p' cs
44 where p' = dontReplace c p