3 ms·
I'll provide a solution for your 'trivial example' in something like Haskell. I hope you see a pattern. Suppose you have a somehow defined the types State, Pe
by eru 19y ago
I'll provide a solution for your 'trivial example' in something like Haskell. I hope you see a pattern.
Suppose you have a somehow defined the types State, Permutation and Hash - and the following functions in terms of them:
-- A function to extract the current permutation
extract :: State -> Permutation
-- A function to step to the next state
next :: State -> State
-- Of course you need a way to see if a particular permutation
-- does actually match the password
try :: Hash -> Permutation -> Bool
-- And an initial State - perhaps corresponding to the identity
-- permutation - to start things
init :: State
Now you can crack passwords:
crack :: Hash -> [Permutation]
crack hash = filter (try hash) perms
where states = iterate next init
perms = map extract states
iterate produces the new states - the results so far are collected with map and filter. Because functional data structures are usually ephemeral you can just predict that intermediate values are actually final.
I hope this was helpful. Please do not hesitate to ask any questions.