Skip to content

Instantly share code, notes, and snippets.

@mackenziestarr
Created August 29, 2017 19:57
Show Gist options
  • Save mackenziestarr/f8936e37bac869ed6483672c8ec35b8a to your computer and use it in GitHub Desktop.
Save mackenziestarr/f8936e37bac869ed6483672c8ec35b8a to your computer and use it in GitHub Desktop.
(ns sha256-guess.core
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]))
(defn- sha256-digest [bs]
(doto (MessageDigest/getInstance "SHA-256") (.update bs)))
(defn sha256 [msg]
(-> msg .getBytes sha256-digest .digest DatatypeConverter/printHexBinary))
(def hash-to-find (clojure.string/upper-case "72abfb5ccfc6360523dc30dbe2ac352b926db4e46617fe6dcb70c53146cd224c"))
(def dict (clojure.string/split-lines (slurp "./Resources/dictionary.txt")))
(def ab-words (filter #(= 0 (clojure.string/index-of % "AB")) dict))
(defn compare-hash [phrase]
(when (= hash-to-find (sha256 phrase) phrase)))
(defn -main []
(let [permutations (for [x ab-words y dict] (str x " " y))
guess (some compare-hash permutations)]
(println (str "answer: " guess))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment