Create a gist now

Instantly share code, notes, and snippets.

@k2nr /core.clj
Created Feb 11, 2014

(ns md5.core
(:require [clojure.core.reducers :as r]
[clojure.string :as s])
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]))
(defn ^String hexdigest [^String s]
(let [digester (MessageDigest/getInstance "MD5")]
(. digester update (.getBytes s))
(DatatypeConverter/printHexBinary (.digest digester))))
(defn ^Boolean match? [^String salt ^String pass ^String digest]
(= digest (hexdigest (str salt "$" pass))))
(defn ^String pad [^Integer n x]
(if (> n (.length (str x)))
(recur n (str 0 x))
(str x)))
(defn find-password [salt pw]
(->> (range 1000000)
(map #(pad 6 %))
(filter #(match? salt % pw))))
(time (dotimes [n 1000000]
(pad 6 n)))
(time (into [] (find-password "hoge" (s/upper-case "4b364677946ccf79f841114e73ccaf4f"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment