Last active
June 13, 2016 23:58
-
-
Save jaydeesimon/2dfadd016de2e9310108132d9e7a0825 to your computer and use it in GitHub Desktop.
Got sucked in
This file contains 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 email-jonas.core | |
(:import (java.util Base64))) | |
(defn build-cipher [xs] | |
(let [[frst scnd] (partition (int (/ (count xs) 2)) xs)] | |
(merge (zipmap frst scnd) (zipmap scnd frst)))) | |
(def ciphers (merge (build-cipher "abcdefghijklmnopqrstuvwxyz") | |
(build-cipher "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))) | |
(defn decode-base64 [s] | |
(String. (-> (Base64/getDecoder) (.decode s)))) | |
(defn decode-rot13 [s] | |
(apply str (map #(get ciphers % %) s))) | |
(comment | |
"From https://jonase.github.io/nil-recur/pages/about.html" | |
(decode-rot13 (decode-base64 "d2JhbmYucmF5aGFxQHR6bnZ5LnBieg==")) | |
) | |
This file contains 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 email-jonas.core | |
(:import (java.util Base64))) | |
(def alphabet "abcdefghijklmnopqrstuvwxyz") | |
(defn shiftable? [c] | |
((set alphabet) c)) | |
(defn shift [n direction c] | |
(if (not (shiftable? c)) | |
c | |
(let [normalize (fn [i] (mod (- i (int \a)) (count alphabet))) | |
letter-idx (normalize (Math/abs (direction n (int c))))] | |
(get alphabet letter-idx)))) | |
(defn decode-base64 [s] | |
(String. (-> (Base64/getDecoder) (.decode s)))) | |
(defn decode-rot13 [s] | |
(apply str (map (partial shift 13 -) s))) | |
(comment | |
"From https://jonase.github.io/nil-recur/pages/about.html" | |
(decode-rot13 (decode-base64 "d2JhbmYucmF5aGFxQHR6bnZ5LnBieg==")) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment