Skip to content

Instantly share code, notes, and snippets.

@TomLisankie
Created September 11, 2019 17:02
Show Gist options
  • Save TomLisankie/f7a6f57f725116146d28b5dcb800ffbc to your computer and use it in GitHub Desktop.
Save TomLisankie/f7a6f57f725116146d28b5dcb800ffbc to your computer and use it in GitHub Desktop.
(ns cryptopals-clj.core)
(defn hex-string->base64-string
"converts hex string to base64 string"
[original-hex-string]
(let [hex-string->hex-byte-array (fn [hex-string]
(let [convert (fn [string hex-bytes]
(if (empty? string)
hex-bytes
(recur (rest (rest string)) (conj hex-bytes (Long/decode (str "0x" (first string) (second string)))))))]
(byte-array (convert hex-string []))))
hex-byte-array->base64-byte-array (fn [hex-byte-array]
(.encode (java.util.Base64/getEncoder) hex-byte-array))
base64-byte-array->base64-string (fn [base64-byte-array]
(apply str (map char base64-byte-array)))]
(->> original-hex-string hex-string->hex-byte-array hex-byte-array->base64-byte-array base64-byte-array->base64-string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment