-
lumo.
User deleted
CODICEimport Data.List (elemIndex)
combinationId :: Eq a => [a] -> [a] -> Maybe Integer
combinationId alphabet string =
let a = toInteger $ length alphabet
n = toInteger $ length string
result = baseCombinationDistance alphabet string
in
case result of
Just distance -> Just $ distance + (a^n - 1) `div` (a - 1)
Nothing -> result
baseCombinationDistance alphabet [] = Just 0
baseCombinationDistance alphabet (x : xs) =
let maybePos = x `elemIndex` alphabet
in
case maybePos of
Just pos ->
let result = baseCombinationDistance alphabet xs
a = toInteger $ length alphabet
n = toInteger $ length xs
in
case result of
Just steps -> Just $ (toInteger pos) * a ^ n + steps
Nothing -> Nothing
Nothing -> Nothing
main = do
putStr "Insert how many password are generated each second: "
pwdPerSecIn <- getLine
putStr "Insert the password to find: "
password <- getLine
let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\\:;\"\\'<>,.?/"
let combination = combinationId alphabet password
let pwdPerSec = read pwdPerSecIn :: Integer
let msg = case combination of
Just id -> "Password found after " ++ show id ++ " steps in " ++ (show $ id `div` pwdPerSec) ++ " seconds."
Nothing -> "Password not found."
putStrLn msg.