rlm@0: (ns coderloop.decrypt rlm@0: (:use [clojure.contrib rlm@0: [duck-streams :only [read-lines]] rlm@0: [seq :only [find-first]] rlm@0: [string :only [map-str]] rlm@0: [combinatorics :only [cartesian-product]]]) rlm@0: (:use rlm.shell-inspect) rlm@0: (:use [clojure [string :only [split]]]) rlm@0: (:import Crypt)) rlm@0: rlm@0: (def t "/home/r/coderloop-test/test.txt") rlm@0: rlm@0: (defn strcat [coll] rlm@0: (apply str coll)) rlm@0: rlm@0: (def numerals [0 2 4 8 ]) rlm@0: rlm@0: (defn crypt [salt s] rlm@0: (Crypt/crypt salt s)) rlm@0: rlm@0: (defn cross-text [text] rlm@0: (let [symbols (filter rlm@0: (fn [s] (<= (count s) 8)) rlm@0: (split (.toLowerCase text) #"[^a-z]+"))] rlm@0: (filter rlm@0: (fn [s] rlm@0: (let [len (count s)] rlm@0: (and rlm@0: (>= len 5) rlm@0: (<= len 8)))) rlm@0: (map (partial apply str) rlm@0: (cartesian-product symbols numerals symbols))))) rlm@0: rlm@0: (defn process-file [f] rlm@0: (let [file (read-lines f) rlm@0: [salt pass] (map (partial apply str) (split-at 2 (first file))) rlm@0: text (strcat (interleave (repeat \newline) (rest file)))] rlm@0: (find-first (fn [s] (= (str salt pass) (crypt salt s))) rlm@0: (cross-text text)))) rlm@0: rlm@0: rlm@0: (if (command-line?) rlm@0: (println (process-file (first *command-line-args*))))