#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname caesar-file) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(require racket/string) (require 2htdp/batch-io)
(check-expect (shift #\d 3) #\g)
(check-expect (shift #\N 6) #\T)
(check-expect (shift #\4 0) #\4)
(define (shift ch key)
(integer->char (+ key (char->integer ch))))
(check-expect (encrypt "hello" 1 false) "ifmmp")
(check-expect (encrypt "Hello" 1 true) "IFMMP")
(define (encrypt msg key upcase?)
(list->string
(map (λ(c) (shift (if upcase? (char-upcase c) c) key))
(string->list msg))))
(define (encryptFile in-file out-file key upcase?)
(write-file
out-file
(string-join (map (λ(ln) (encrypt ln key upcase?))
(read-lines in-file))
"\n")))
(require (planet "main.rkt" ("nah22" "racketui.plt" 1 3)))
(web-launch
"!Encryptor!"
(function "Use this program to encrypt your most secret files."
(encryptFile ["Input file" filename]
["Output file name" string+]
["Secret key" number]
["Uppercase?" boolean]
-> ["Encrypted file" filename])))