Sha256: a18b2f37c81fdd7c45dc957ee5f1cd6dd63e003d25d40c1bb3e356d9d1a4c9d2

Contents?: true

Size: 1.42 KB

Versions: 396

Compression:

Stored size: 1.42 KB

Contents

;;; atbash-cipher.el --- Atbash-Cipher (exercism)

;;; Commentary:
;;;
;;; Adapted from the Common Lisp example, at
;;; https://github.com/exercism/xlisp/blob/master/atbash-cipher/example.lisp


;;; Code:

(defun encode (plaintext)
  "Encode PLAINTEXT to atbash-cipher encoding."
  (to-string (group (to-cipher-seq plaintext))))

(defun to-string (seq)
  "Convert SEQ of characters to a string."
  (concatenate 'string seq))

(defun group (seq &optional group-size)
  "Group SEQ into chunks of size GROUP-SIZE."
  (let ((length (or group-size 5)))
    (loop
     for c in seq and i from 1
     collect c
     when (and (not (= i (length seq)))
               (zerop (mod i length)))
     collect ?\ )))


(defun to-cipher-seq (plaintext)
  "Convert PLAINTEXT to a ciphered sequence."
  (cleanup-ciphered-seq (map 'list #'encipher plaintext)))

(defun cleanup-ciphered-seq (seq)
  "Clean values of char code 0 from SEQ."
  (remove 0 seq))

(defun encipher (c)
  "Encipher the character C."
  (cond ((alpha-char-p c) (opposite-char (downcase c)))
        ((digit-char-p c) c)
        (t 0)))

(defun digit-char-p (c)
  "Determine if char C is numeric."
  (and
   (>= c ?0)
   (<= c ?9)))




(defun alpha-char-p (c)
  "Determine if char C is alphabetic."
  (and
   (>= c ?A)
   (<= c ?z)))



(defun opposite-char (c)
  "Find the opposite char of argument character C."
  (- ?z
     (- c ?a)))


(provide 'atbash-cipher)
;;; atbash-cipher.el ends here

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.179 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.178 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.177 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.176 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.175 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.174 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.173 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.172 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.171 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.170 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.169 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.167 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.166 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.165 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.164 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.163 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.162 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.161 tracks/elisp/exercises/atbash-cipher/example.el
trackler-2.2.1.160 tracks/elisp/exercises/atbash-cipher/example.el