Skip to content

Instantly share code, notes, and snippets.

@jukworks
Created October 4, 2013 12:44
Show Gist options
  • Save jukworks/6825357 to your computer and use it in GitHub Desktop.
Save jukworks/6825357 to your computer and use it in GitHub Desktop.
ROT-13 encryption in Clojure
(defn shift13 [start n]
(let [s (int start)
c (int n)]
(char (if (<= s c (+ s 25))
(+ s (mod (+ (- c s) 13) 26))
n))))
(defn rot13 [st]
(->> (map (fn [x]
(let [n (int x)]
(cond
(<= 65 n 90) (shift13 \A x)
(<= 97 n 122) (shift13 \a x)
:else x)))
(seq st))
(apply str)))
;; (rot13 "hEllo") => "uRyyb"
;; (rot13 "uRyyb") => "hEllo"
;; (rot13 "The quick brown fox jumps over the lazy dog.") => "Gur dhvpx oebja sbk whzcf bire gur ynml qbt."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment