Created
January 20, 2020 18:49
-
-
Save zenon/5a02bf49fdf57dc1dae68f5d33cb3c36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#lang racket | |
(define cyphertext | |
"") | |
(define code | |
#hash(("a" . "_") | |
("b" . "_") | |
("c" . "_") | |
("d" . "_") | |
("e" . "R") | |
("f" . "_") | |
("g" . "_") | |
("h" . "_") | |
("i" . "_") | |
("j" . "_") | |
("k" . "_") | |
("l" . "E") | |
("m" . "_") | |
("n" . "T") | |
("o" . "_") | |
("p" . "_") | |
("q" . "_") | |
("r" . "_") | |
("s" . "_") | |
("t" . "_") | |
("u" . "N") | |
("v" . "_") | |
("w" . "_") | |
("x" . "_") | |
("y" . "_") | |
("z" . "_"))) | |
(define (replacer a b) (string-replace b a (dict-ref code a))) | |
(define text (foldl replacer cyphertext (dict-keys code))) | |
(display text) | |
(println "") | |
; max is 26 for a..z | |
(define (char-plus-int c n max) | |
(integer->char (+ (modulo (+ (- (char->integer c) 97) n) max) 97))) | |
(define (shifter text n) | |
(let ((letters (string->list text))) | |
(list->string (map (lambda (c) (char-plus-int c n 26)) letters)) | |
)) | |
;(map (lambda (n) (println n) (display (shifter cyphertext n)) (println "")) (range 0 27)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment