Skip to content

Instantly share code, notes, and snippets.

@berdario
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berdario/3a2b9e11f0770ff50aeb to your computer and use it in GitHub Desktop.
Save berdario/3a2b9e11f0770ff50aeb to your computer and use it in GitHub Desktop.
Take all the possible letter substitutions in a password, and append to it a list of possible years
import System.Environment (getArgs)
import Data.Map (fromList, findWithDefault)
import qualified Data.Set as S
nub = S.toList . S.fromList
applyIf f = (\x flag -> if flag then f x else x)
flagCombinations n = sequence $ replicate n [True, False]
leet x = nub $ map (zipWith (applyIf substitute) x) $ flagCombinations $ length x
substitutions = fromList [('o','0'), ('a','4'), ('s','5')]
substitute x = findWithDefault x x substitutions
years = [1900..2014]
appendYears x = map ((x ++) . show) years
transform = concatMap (concatMap appendYears . leet)
main = do
infile:_ <- getArgs
passwords <- fmap lines $ readFile infile
putStrLn $ unlines $ transform passwords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment