Skip to content

Instantly share code, notes, and snippets.

@omegatakuma
Created August 6, 2012 15:51
Show Gist options
  • Save omegatakuma/3275860 to your computer and use it in GitHub Desktop.
Save omegatakuma/3275860 to your computer and use it in GitHub Desktop.
[Gauche]シーザー暗号
(define base (string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(define base2 (string->list "abcdefghijklmnopqrstuvwxyz"))
(define (caesar lst n)
(let ((solve (append (drop base n) (take base n)))
(solve2 (append (drop base2 n) (take base2 n))))
(let loop ((lst lst)
(n 0)
(result '()))
(cond
((null? lst)
(reverse result))
((> n 25)
(loop (cdr lst) 0 result))
((eq? (car lst) (list-ref base n))
(loop (cdr lst) 0 (cons (list-ref solve n) result)))
((eq? (car lst) (list-ref base2 n))
(loop (cdr lst) 0 (cons (list-ref solve2 n) result)))
(else (loop lst (+ n 1) result))))))
;(define (main args)
; (print (list->string (caesar (string->list "I Love you") 3))))
;=> LOryhbrx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment