I want to program a shift or caesar cipher in the scheme, but not using wire I use a list instead Define the message (define (theophox)) (define k 4) (define A (char-> integer # \ A)) (define Z (( - (- (- (- (- (- (Four-> Integer (car message)) K) - & gt; () () () (defined (cipher message) (if (empty message) ( Cipher message))) (define (Assistant) (cipher message)) I know that in which part I should use modules and compare it with A and Z limitations, but my question is how. (Car message) is converted to a four and then in an integer I can add the value of Kashmir, and then display it's value to convert it back from the integer.
And map-based solutions But how to do this with conversions like just above a list and above?
Thanks in advance
Here is a common version that allows lists, symbols, strings, and characters. Note that I have not written the loop manually (doing so is painful for me when the map
is readily available);
This version uses (for string-map
) and ( cut
). (If you are writing the loops manually, and expanding the cut
by hand, you will be able to use it in a plain plan.)
(Srfi / 13 sfii / 26) ;; Define for racket (caesar x shift) (cod (four? X) (caesar-four x shift) (string? X) (caesar-string x inning)) ((symbol? X) (caesar-symbol X Change () () ((List-x) (Caesar-list x shift) (and (error "unknown type" x)) (define (Caeser-four variation) (if (four-alphabetical? (* (* Ord (char-> integer ch)) (lower (modulo ord 32)) (upper (lower lower)) (integer-> char (+ upper (modulo (+ less shift) 26))))) (define (cesar-string str poly) ( String-map (cut quasar-four and lefthium; & gt; variation) str) (define (Caeser-symbol sim shift) (string-> symbol (cesar-string) (symbol-> string cam)
& gt; (Caesar '(TEFOX) 4)' (XLJSB)> (Caesar '(XLJSB) 22)' (TEFF O x)
Comments
Post a Comment