bruteforce


SUBMITTED BY: Guest

DATE: Sept. 7, 2014, 8:12 p.m.

FORMAT: Text only

SIZE: 738 Bytes

HITS: 842

  1. import Data.List
  2. alpha = ['a'..'z']
  3. alpha_l = [ [c] | c <- alpha ]
  4. rec base level maxlevel =
  5. if level < maxlevel-1
  6. then
  7. rec [ base_element ++ [newchar] | base_element <- base , newchar <- alpha ] (level+1) maxlevel
  8. else
  9. base
  10. all_sizes maxsize =
  11. [1..maxsize]
  12. process maxsize =
  13. concat [ (rec alpha_l 0 s) | s <- (all_sizes maxsize) ]
  14. pretty_print list =
  15. putStrLn (intercalate "\n" list)
  16. test_combination hash try =
  17. reverse try == hash
  18. bruteforce hash maxsize =
  19. head [ try | try <- (process maxsize), (test_combination hash try) ]
  20. main =
  21. -- pretty_print (process 6)
  22. -- print (process 2)
  23. putStrLn (bruteforce "bcdefg" 1