Sha256: bb1a5c44d29fa7ab8fe299639cf94530647b7d9ca090196f71c4f71306f4a552

Contents?: true

Size: 867 Bytes

Versions: 396

Compression:

Stored size: 867 Bytes

Contents

(defpackage #:atbash-cipher
  (:use #:common-lisp)
  (:export #:encode))

(in-package #:atbash-cipher)

(defun to-string (seq)
  (concatenate 'string seq))

(defun group (seq &optional (group-size 5))
  (loop
     for c in seq and i from 1
     collect c
     when (and (not (= i (length seq)))
               (zerop (mod i group-size)))
     collect #\Space))

(defun cleanup-ciphered-sequence (seq)
  (remove (code-char 0) seq))

(defun opposite-char (c)
  (code-char
   (- (char-code #\z)
      (- (char-code c)
         (char-code #\a)))))

(defun encipher (c)
  (cond ((alpha-char-p c) (opposite-char (char-downcase c)))
        ((digit-char-p c) c)
        (t (code-char 0))))

(defun to-cipher-sequence (plaintext)
  (cleanup-ciphered-sequence (map 'list #'encipher plaintext)))

(defun encode (plaintext)
  (to-string (group (to-cipher-sequence plaintext))))

Version data entries

396 entries across 396 versions & 1 rubygems

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