Created
September 4, 2013 07:46
-
-
Save joshy/6433895 to your computer and use it in GitHub Desktop.
Simple caesar encode/decode of strings in clojure.
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 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