new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
5
Task/Caesar_cipher/Racket/caesar_cipher-2.rkt
Normal file
5
Task/Caesar_cipher/Racket/caesar_cipher-2.rkt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
> (define s (encrypt "The five boxing wizards jump quickly."))
|
||||
> s
|
||||
"Uif gjwf cpyjoh xjabset kvnq rvjdlmz."
|
||||
> (decrypt s)
|
||||
"The five boxing wizards jump quickly."
|
||||
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