caesar.scm 597 B

123456789101112131415161718192021222324252627
  1. ;;;
  2. ;;; Caesar encipher and decipher, including ROT13
  3. ;;;
  4. ;;; Copyright 2016 Jason K. MacDuffie
  5. ;;; License: GPLv3+
  6. ;;;
  7. ;; This is easy to implement with our tabula recta
  8. (define (caesar-encipher pt-in key-in)
  9. ;; The key should be an integer 0 to 25
  10. (define l (integer->letter key-in))
  11. (map (lambda (c) (letter+ c l))
  12. pt-in))
  13. (define (caesar-decipher ct-in key-in)
  14. ;; Inverse of caesar-encipher
  15. (define l (integer->letter key-in))
  16. (map (lambda (c) (letter- c l))
  17. ct-in))
  18. (define (rot13 t)
  19. ;; For rot13, encipher and decipher is the same
  20. (caesar-encipher t 13))