Created
August 6, 2012 15:51
-
-
Save omegatakuma/3275860 to your computer and use it in GitHub Desktop.
[Gauche]シーザー暗号
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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