Skip to content

Instantly share code, notes, and snippets.

@zenon
Created January 20, 2020 18:49
Show Gist options
  • Save zenon/5a02bf49fdf57dc1dae68f5d33cb3c36 to your computer and use it in GitHub Desktop.
Save zenon/5a02bf49fdf57dc1dae68f5d33cb3c36 to your computer and use it in GitHub Desktop.
#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