Skip to content

Instantly share code, notes, and snippets.

@aboekhoff
Created January 12, 2010 08:11
Show Gist options
  • Save aboekhoff/274994 to your computer and use it in GitHub Desktop.
Save aboekhoff/274994 to your computer and use it in GitHub Desktop.
;;;; point-free SHA1 hash
(import java.security.MessageDigest)
(defmacro >>
"(>> 1 2 3 4 5) => (2 3 4 5 1)"
[x & xs]
`(~@xs ~x))
(defn sha1 [#^String s]
(-> (doto (MessageDigest/getInstance "SHA1")
.reset
(.update (.getBytes s)))
.digest
(>> map #(-> % (bit-and 0xff) Integer/toHexString))
(>> apply str)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment