Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Caesar-cipher/Racket/caesar-cipher.rkt
Normal file
19
Task/Caesar-cipher/Racket/caesar-cipher.rkt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#lang racket
|
||||
|
||||
(define A (char->integer #\A))
|
||||
(define Z (char->integer #\Z))
|
||||
(define a (char->integer #\a))
|
||||
(define z (char->integer #\z))
|
||||
|
||||
(define (rotate c n)
|
||||
(define cnum (char->integer c))
|
||||
(define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26))))
|
||||
(cond [(<= A cnum Z) (shift A)]
|
||||
[(<= a cnum z) (shift a)]
|
||||
[else c]))
|
||||
|
||||
(define (caesar s n)
|
||||
(list->string (for/list ([c (in-string s)]) (rotate c n))))
|
||||
|
||||
(define (encrypt s) (caesar s 1))
|
||||
(define (decrypt s) (caesar s -1))
|
||||
Loading…
Add table
Add a link
Reference in a new issue