Skip to content

Instantly share code, notes, and snippets.

@jaydeesimon
Last active June 13, 2016 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydeesimon/2dfadd016de2e9310108132d9e7a0825 to your computer and use it in GitHub Desktop.
Save jaydeesimon/2dfadd016de2e9310108132d9e7a0825 to your computer and use it in GitHub Desktop.
Got sucked in
(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=="))
)
(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