Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Last active August 29, 2015 14:00
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 jcromartie/11052252 to your computer and use it in GitHub Desktop.
Save jcromartie/11052252 to your computer and use it in GitHub Desktop.
Vigenere cipher in a completely pointless (I mean, um, point-free) style
;; an appropriate prelude...
(def parpar (partial partial partial))
(def parapply (parpar apply))
(def parconj (parpar conj))
;; one convenient constant
(def char-offset (int \A))
(def ^{:arglists '[[key text]]
:doc "Enciphers plaintext using key (padding by repeating the key if
necessary"}
vigenere
(comp (parapply str)
(parapply map
(comp char
(partial + char-offset)
(parapply mod)
(parconj '(26))
(parapply +)
(partial map (comp -
(partial - char-offset)
int))
list))
(parapply update-in)
(parconj (list [0] cycle))
(partial mapv (memfn toUpperCase))
list))
(assert (= (vigenere "counton" "vigenerecipher")
"XWARGSEGQCCASE"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment