Created
September 11, 2019 17:02
-
-
Save TomLisankie/f7a6f57f725116146d28b5dcb800ffbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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