Q:

Encrypt Scheme: [() is not a pair]

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?

A:

Óscar López's answer pointed out some of the problems that you might be having in this code, but I think it's important to specifically address the error message that you mentioned: () is not a pair.  This means that you're calling a function that expects a pair (so typical candidates would be car and cdr on an empty list.  Let's take a look at your code and see where this could happen:
(define help
      (lambda (ls1 ls2 ls3)
         (if (null? ls1) '()                                 ; a
           (if (and (null? ls2) (null? ls3)) ls1             ; b
              (if (equal? (car ls1) (car ls2))               ; c
                  (cons (car ls3) (help (cdr ls1) ls2 ls3))  ; d 
                  (help ls1 (cdr ls2) (cdr ls3))))))         ; e

Lines a and b don't call any functions that expect a pair, so you shouldn't run into this problem there.
In line c, you do (car ls1) and (car ls2).  Line a ensured that ls1 isn't (), but ls2 still could be, since b only checked that it's not the case that both ls2 and ls3 are ();  either one alone still could be.
In line d, you've got (car ls3) and (cdr ls1).  Line a ensured that ls1 isn't (), but ls2 still could be for the same reason given in the previous case.
Line e has (cdr ls2) and (cdr ls3), and both of these could cause a problem, because either one of them (but not both) could be ().

Though your title didn't say it, your question mentioned that this is actually happening with car, which means that it's not happening in e, which leaves c and d. It's either happening in (car ls2) in c or in (car ls3) in d.
If you're using Dr. Racket to run your code, the IDE should highlight the place where the bad call happened (something like what's shown in the screenshot in this answer).

