Skip to content

Instantly share code, notes, and snippets.

@athos athos/core.clj
Last active Jan 26, 2017

What would you like to do?
「数字6桁パスワードのハッシュ値の総当たり、PHPなら約0.25秒で終わるよ( )」で、PHPに比べてClojureがやたら遅いという話だったので、Clojureのコードをいろいろいじってみた。
(ns six-length.core
(:require [clojure.core.reducers :as r]
[clojure.string :as s])
(:import [ MessageDigest]
[javax.xml.bind DatatypeConverter]))
(set! *warn-on-reflection* true)
(def hexdigest
(let [digester (MessageDigest/getInstance "MD5")]
(fn [^String s]
(doto digester
(.update (.getBytes s)))
(DatatypeConverter/printHexBinary (.digest digester)))))
(defn find-password [salt pw]
(let [pw (s/upper-case pw)]
(->> (range 0 1000000)
(map #(let [s (str "000000" %), len (count s)]
(subs s (- len 6) len)))
(map (fn [_] [_ (hexdigest (str salt "$" _))]))
(filter #(= pw (second %))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.