I finally have been able to spend some time with newLisp. It’s a lot of fun and I have a feeling I’ll be keeping it in the arsenal. Besides messing around with the obvious web/cgi stuff with it, I wrote a scraper and ported an implementation of the ARC4 encryption scheme.
(define (crypt data key) (let ((x 0) (y 0) (box (sequence 0 255)) (out '())) (for (i 0 255) (setq x (% (+ x (box i) (char (key (% i (length key))))) 256)) (swap (box i) (box x))) (setq x 0) (for (i 0 (- (length (explode data)) 1)) (setq x (% (+ x 1) 256)) (setq y (% (+ y (box x)) 256)) (swap (box x) (box y)) (push (char (^ (char (data i)) (box (% (+ (box x) (box y)) 256)))) out)) (reverse out)))
The crazy thing about lisp is I can take a small proc like that and carry it around for a week thinking of, and usually finding ways to make it more succinct. I never do that with PHP, write it, yawn, forget it. Lisp beats sudoku while on the train anyway
Here’s the python version for comparison:
def rc4crypt(data, key): x = 0 box = range(256) for i in range(256): x = (x + box[i] + ord(key[i % len(key)])) % 256 # print x box[i], box[x] = box[x], box[i] x = 0 y = 0 out = [] for char in data: x = (x + 1) % 256 y = (y + box[x]) % 256 box[x], box[y] = box[y], box[x] out.append(hex(ord(char) ^ box[(box[x] + box[y]) % 256])) return out
Note: this post was lifted from my old blog so I could test out the code hilighting.


