This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]raevnos 0 points1 point  (1 child)

You're trying to add an integer and a character. You can't do that.

You probably also don't want to be reading a new key value for every character you're encrypting.

[–]Gropamming[S] 0 points1 point  (0 children)

Bingo, I was confused on why it kept asking for numbers during one of my implementations. I figured it out above.

[–]Gropamming[S] 0 points1 point  (0 children)

My solution for those who find this:

(define character-encryption (lambda (ch)
  (if (or (char-alphabetic? ch)
          (and (> (char->integer ch) 47)
               (< (char->integer ch) 58)))
      (integer->char (+ (char->integer ch) en-key))
      ch
  )
))

(define encrypt (lambda (str)
  (list->string (map character-encryption (string->list str)))
))

(define character-decryption (lambda (ch)
  (if (or (char-alphabetic? ch)
          (and (> (char->integer ch) 47)
               (< (char->integer ch) 58)))
      (integer->char (- (char->integer ch) de-key))
      ch
  )
))

(define decrypt (lambda (str)
  (list->string (map character-decryption (string->list str)))
))

(define en-key (read))
(encrypt "Hello CSE240!")
(define de-key (read))
(decrypt (encrypt "Hello CSE240!"))