November 10, 2020

We give a function that performs encryption, and leave it to the reader to wrap that in a function that handles files:

(define (memfrob str)
   (define (frob c)
     (integer->char (bitwise-xor (char->integer c) 42)))
   (list->string (map frob (string->list str))))

 > (memfrob (memfrob "Programming Praxis"))
   "Programming Praxis" 

You can run the program at

Pages: 1 2

2 Responses to “Memfrob”

  1. chaw said

    A quick solution using standard Scheme:

    (import (scheme base)
            (scheme write)
            (only (srfi 60)
            (only (org eip10 okmij myenv)
    (define (memfrob-byte byt)
      (bitwise-xor byt 42))
    (assert (equal? '(42 0 43 41)
                    (map memfrob-byte '(0 42 1 3))))
    (define (memfrob-bytevector bytvec)
      (let* ((n (bytevector-length bytvec))
             (r (make-bytevector n)))
        (do ((i 0 (+ i 1)))
            ((>= i n) r)
          (bytevector-u8-set! r i (memfrob-byte (bytevector-u8-ref bytvec i))))))
    (assert (equal? #u8(42 0 43 41)
                    (memfrob-bytevector #u8(0 42 1 3))))
    (define (memfrob-string str)
      (utf8->string (memfrob-bytevector (string->utf8 str))))
    (assert (string=? "Hello, World!"
                      (memfrob-string (memfrob-string "Hello, World!"))))

  2. Alex B said

    In Python:

    def memfrob(msg):
        return bytes(c ^ 42 for c in msg)

    Input argument must be a bytes-like object.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: