나는 실행을 시도한 프로그램에 대해 질문이있었습니다. Encrypt는 메시지, 공개 키 및 개인 키를 사용하고 공개 키의 메시지에있는 문자가 개인 키의 문자로 변경된 메시지를 반환합니다.암호화 [Petite Chez Scheme]
예를 들어 (암호화 "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
계획 디버그 꽤 쉽게 :
내가 거기를 떠날거야. 스테퍼가 당신을 어떤 단계로 멈추게합니까? – LostLin