fork download
  1. #lang racket
  2.  
  3. (require (only-in srfi/13 string-map))
  4.  
  5. (define (rotate text shift)
  6. (string-map (lambda (ch)
  7. (let ((ch (if (char-lower-case? ch)
  8. (char-upcase ch)
  9. ch))
  10. (a (char->integer #\A)))
  11. (if (char<=? #\A ch #\Z)
  12. (integer->char (+ (modulo (+ (- (char->integer ch) a) shift 26) 26) a))
  13. ch))) text))
  14.  
  15. (define *text* "I LOVE YOU.")
  16. (define *enc-text* (rotate *text* 3)) ; 暗号化
  17. (define *dec-text* (rotate *enc-text* -3)) ; 復号化
  18. (for-each (lambda (x)
  19. (displayln (format "~a: ~a" (car x) (cadr x))))
  20. `(("文字列" ,*text*) ("暗号化" ,*enc-text*) ("復号化", *dec-text*)))
Success #stdin #stdout 0.55s 90924KB
stdin
Standard input is empty
stdout
Standard output is empty