I have previously talked about arcfour
and CipherSaber and provided
implementations in C. For fun, I made an implementation of arcfour in
Emacs lisp (elisp), and built upon that to make a CipherSaber
implementation in elisp. Check it out with Git,

If you don't have Git (yet), you can follow that link to use the web
interface. The relevant files are arcfour.el and
ciphersaber.el. There are some test vectors in there that
I won't show here. Here is the arcfour implementation,

(defunrc4-init-state()"Initialize the arcfour state vector."(interactive)(setqrc4-state(make-vector2560))(setqrc4-i0)(setqrc4-j0)(let(i)(dotimes(i256rc4-state)(asetrc4-stateii))))(defunrc4-swap(ij)"Swap two elements in the state vector."(let((temp(arefrc4-statei)))(asetrc4-statei(arefrc4-statej))(asetrc4-statejtemp)))(defunrc4-key-sched(key)"Arcfour key-scheduler: initialize state from key."(interactive"sEnter key: ")(let((j0)i)(dotimes(i256rc4-state)(setqj(%(+j(arefrc4-statei)(arefkey(%i(lengthkey))))256))(rc4-swapij))))(defunrc4-gen-byte()"Generate a single byte."(interactive)(setqrc4-i(%(1+rc4-i)256))(setqrc4-j(%(+rc4-j(arefrc4-staterc4-i))256))(rc4-swaprc4-irc4-j)(arefrc4-state(%(+(arefrc4-staterc4-i)(arefrc4-staterc4-j))256)))

For the sake of simplicity it uses some global variables to store the
cipher state. It would be better if the state was returned as a list,
continuation, or closure. That way we could run a bunch of different
ciphers at the same time.

And this provides interactive functions so that they can be called by
a user right on the buffer being used, with M-x rc4-buffer.

You may run into encoding issues with encrypted regions. The
CipherSaber implementation below gets around this problem by turning
off multi-byte encoding with set-buffer-multibyte.

In ciphersaber.el we apply these functions. The
CipherSaber functions can be called with M-x
cs-encrypt-buffer and M-x cs-decrypt-buffer. Note
that this is only CipherSaber-1, and I leave CipherSaber-2 as an
exercise for the reader :-P.

I didn't bother with save-excursion because I didn't
think it would be important where the point is in the middle of an
encrypted file. Feel free to add it, though!

These functions could be used to make a minor mode to transparently
encrypt and decrypt CipherSaber files. It could also be modified to
take advantage of Emacs' batch mode to handle CipherSaber
processing right from the shell. But those are other projects!