我有一个关于我一直在尝试运行的程序的问题。Encrypt 获取消息、公钥和私钥,并返回消息,并将公钥中的消息中的字母更改为私钥中的字母。
例如, (encrypt "abcd" "abcd" "efgh") 应该返回 "efgh" 并且 (encrypt "abcl" "abcd" "efgh") 应该返回 "efgl"(来自未公开的消息的字母 -密钥将保持不变)。
我已经编写了一些帮助程序来解决这个问题,但是当我尝试运行它时,我不断收到错误“汽车中的异常,__ 不是一对”。但我不确定有什么问题。如果有人有任何指示,请告诉我。谢谢!
(define encrypt
(lambda (message public-key private-key)
(cond
[(list->string (encrypt-helper (string->list message)
(string->list public-key) (string->list private-key)))])))
(define encrypt-helper
(lambda (msg-ls public-ls private-ls)
(cond
[(null? public-ls) '()]
[(null? private-ls) '()]
[(and (null? public-ls) (null? private-ls)) msg-ls]
[else (cons (encrypt-key (car msg-ls) (car public-ls) (car private-ls))
(encrypt-helper (cdr msg-ls) (cdr public-ls) (cdr private-ls)))])))
;should encrypt all letters in msg-ls. not working correctly
(define encrypt-key
(lambda (char pub-key priv-key)
(cond
[(null? pub-key) char]
[(equal? char (car pub-key)) (car priv-key)]
[else (encrypt-key char (cdr pub-key) (cdr priv-key))])))
;encrypts just one letter, ex: (encrypt-key 'a '(a) '(b)) => b
;works correctly