My program looks now like this:
Code: Select all
; 1) Program that takes in a word(given as a string) plus a number and encrypts the word using Caesar's Cipher in the modulo given as the number:
; Alphabet as parameter plus one whitespace at index 0
(defparameter *alphabet* " abcdefghijklmnopqrstuvwxyz,.0123456789")
; Finds the index of char in *alphabet*:
(defun alphabet-index (char)
(position char *alphabet*))
; Finds the char shifted n places to the right in the alphabet:
(defun rotate (char n)
(elt *alphabet* (mod (+ (alphabet-index char) n)(length *alphabet*))))
; makes the rotate function accesable for map
(defun e-helper (n)
#'(lambda (char)
(rotate char n)))
; Returns the encrypted string
(defun encrypt (str n)
(map 'string (e-helper n) str))
; 2) Program that decrypts a word given as a string (first argument) using Caesar's cipher in the modulo given (second argument)
; Rotates the encrypted chars back to their original meaning
(defun rotate-back (char n)
(elt *alphabet* (mod (- (alphabet-index char) n)(length *alphabet*))))
; Makes the rotate-back function accesable for map
(defun d-helper (n)
#'(lambda (char)
(rotate-back char n)))
; Returns the decrypted string
(defun decrypt (str n)
(map 'string (d-helper n) str))
+: NIL is not a number
[Condition of type SIMPLE-TYPE-ERROR]
Some idea what went wrong?