Skip to content

Instantly share code, notes, and snippets.

@joshy
Created September 4, 2013 07:46
Show Gist options
  • Save joshy/6433895 to your computer and use it in GitHub Desktop.
Save joshy/6433895 to your computer and use it in GitHub Desktop.
Simple caesar encode/decode of strings in clojure.
(ns caesar.core)
(def secret "RVAWNUEVFGJVRQREIBEORVHAQRFUNGXHPURAORQVRAGRHPU")
(def text "EINJAHRISTWIEDERVORBEIUNDESHATKUCHENBEDIENTEUCH")
(defn encode
"Encodes the text with shifting each char shift positions"
[text shift]
(apply str (map char (map #(+ (mod (+ shift %) 26) 65) (map int text)))))
(defn decode
"Decodes the secret with shifting each char shift positions"
[secret shift]
(apply str (map char (map #(+ (mod (+ (* -1 shift) %) 26) 65) (map int secret)))))
(defn brute-force
[secret]
(for [i (range 1 27)]
(println i " = " (decode secret i))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment