[ create a new paste ] login | about

Link: http://codepad.org/TPWgYRB9    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Mar 10:
1
2
3
4
5
6
7
8
9
10
11
12
; caesar cipher

(define (caesar n str)
  (define (char-plus c)
    (let ((alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
      (if (not (char-alphabetic? c)) c
        (let ((i (- (char->integer (char-upcase c)) 65)))
          (string-ref alpha (modulo (+ i n) 26))))))
    (list->string (map char-plus (string->list str))))

(display (caesar 3 "PROGRAMMINGPRAXIS")) (newline)
(display (caesar -3 "SURJUDPPLQJSUDALV")) (newline)


Output:
1
2
SURJUDPPLQJSUDALV
PROGRAMMINGPRAXIS


Create a new paste based on this one


Comments: