Define a procedure encrypt that takes three strings: a message to be encrypted and two alphabets, which we will call regular and encrypted. The alphabet strings are both the same length and they do not contain duplicates. For each character in the message, look it up in regular and, if you find it, convert it to the character in the corresponding location of encrypted. For example, if the regular is abc and the encrypted is def, that means that an a in the message will encode as a d, a b encodes as an e, and a c encodes as an f.
i wrote my code as follow:
(define encrypt
(lambda (message regular encrypted)
(define help
(lambda (ls1 ls2 ls3)
(if (null? ls1) '()
(if (and (null? ls2) (null? ls3)) ls1
(if (equal? (car ls1) (car ls2))
(cons (car ls3) (help (cdr ls1) ls2 ls3))
(help ls1 (cdr ls2) (cdr ls3))))))
(list->string (help
(string->list message)
(string->list regular)
(string->list encrypted)))))
I have been trying to get a running. but the result returns Exception in car: () is not a pair
I quite check it many times, but I didn't what I should change. is there anyone can help me?