Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
「数字6桁パスワードのハッシュ値の総当たり、PHPなら約0.25秒で終わるよ(http://z.tokumaru.org/2014/02/6php025.html )」で、PHPに比べてClojureがやたら遅いという話だったので、Clojureのコードをいろいろいじってみた。
(ns six-length.core
(:require [clojure.core.reducers :as r]
[clojure.string :as s])
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]))
(set! *warn-on-reflection* true)
(def hexdigest
(let [digester (MessageDigest/getInstance "MD5")]
(fn [^String s]
(doto digester
(.reset)
(.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.