Ordovim or: How to half ass something with (predictably) crappy results

I love Neal Stephenson’s books. He is the God Uncle of cyberpunk (the Godfather of cyberpunk is, of course, William Gibson). One of Stephenson’s doorstoppers is Cryptonomicon, a MASSIVE, 1100+ page monstrosity jam packed with everything you could want in a historical fiction/sorta cyberpunk novel. It’s got action, World War II code breaking, guest appearances by Alan Turing, digressions on cryptography, a few predictions about the future (internet banking being one of them. Remember, it was published in 1999) and a ton of other things I can’t remember. It even had graphs. GRAPHS for duck’s sake.

Anyway, one of the things I remembered reading about in the book is Ordoemacs. Ordoemacs is the text editor for the paranoid. Everything written in Ordoemacs is automatically encrypted when written to disk. At least, that’s how I remembered it. So I wanted to do something similar, but in Vim. Thus, Ordovim.

(See that ‘half ass’ in the title? Start counting them).

Writing a text editor from scratch is hard, really hard. Especially one with as much power as Vim. So I chose not to bother. A Vim plugin would’ve been easier. (This was my first, but understandable and sane, half ass. I’m nothing if not pragmatic).

“But I have to learn Vimscript to write a plugin. And Vimscript is stoopid! Ugh!“, I whined internally. Vimscript is powerful, no doubt! I mean, just look at all the plugins available. They’re pretty rad. But my lazy bum didn’t want to take the time to sit down and fully learn this kinda ugly language (Spacemacs and Elisp’s distant siren song isn’t helping either). So I decided to learn just enough to help me write this thing. But I soon found out plugins require a greater investment in time and learning than I was inclined to give. So I reduced the requirement from a plugin to a function and a couple of autocommands. (This was my second half ass. Seeing a trend?).

“But you couldn’t possibly do proper encryption with a single function.” I hear you say. And you’re right. Also I knew diddly squat about cryptography. Still don’t, unless you call importing and using a Python library as sufficient cryptographic expertise. And that’s exactly what I did. Simple Crypt is a wrapper around a much more complex and powerful Python library called PyCrypto. It’s a kiddie fence created to protect knuckleheads like me from hurting myself trying to climb the metaphorical jungle gym. It is dead simple to use. And gave me an easy way out from having to actually learn some cryptography.

from simplecrypt import encrypt, decrypt

plain_string = "This do be a string. Fortune prick me if it is not"
password = "yourpassword"

encrypted_string = encrypt(password, plain_string.encode('UTF-8'))
decrypted_string = decrypt(password, encrypted_string.decode('UTF-8'))

It is literally that easy to use. I needed to do nothing else. Ask me what SHA1 stands for and you’ll just get a blank stare. I wrote a dead simple python script with an easy to use encryption library and added a few lines to my vimrc to call that script whenever I opened a file with the extension .ordo.enc (to decrypt it) or closed a file with the extension .ordo (to encrypt it). (Half ass numero très).

The end result? It’s… working? Sort of? Opening an encrypted file automatically decrypts it. But half asses strike back! You can’t close the file or delete the buffer and expect that it will encrypt. Whichever buffer your ‘*.ordo’ file is, only the file in the current buffer gets encrypted. You have to switch to the buffer of the file you want to encrypt before closing it. But hey! It’s working. Right?

“Well that was a fun project!”, I thought in my elation upon completion. “Not half bad!” You know how children can sit in a cardboard box and pretend they’re piloting a spaceship. That was me, thinking I’d just made a working clone of Ordoemacs with some tape and a couple of screws. A true MacGyver is me. And so in the spirit of things, I decided to read that part in Cryptonomicon where they talk about Ordoemacs again.

Recall that I mentioned at the beginning this phrase: ‘Alteast, that’s how I remembered it.’ See that added emphasis on ‘remembered’? Yeah. I’ve been going by memory all this time about how Ordoemacs actually worked. I hadn’t opened that book in quite a while. Here’s the quote from the book:

OrdoEmacs, on the other hand, works exactly like regular Emacs, except that it encrypts everything before writing it out to disk. At no time is plaintext ever laid down on a disk by OrdoEmacs–the only place it exists in its plain, readable form is in the pixels on the screen, and in the volatile RAM of the computer, whence it vanishes the moment power is shut down. Not only that, but it’s coupled to a screensaver that uses the little built-in CCD camera in the laptop to check to see if you are actually there. It can’t recognize your face, but it can tell whether or not a vaguely human-shaped form is sitting in front of it, and if that vaguely human-shaped form goes away, even for a fraction of a second, it will drop into a screen-saver that will blank the display and freeze the machine until such time as you type in a password, or biometrically verify your identity through voice recognition.

Oh.

That’s.. well.. that’s definitely not what I created.

Here was my biggest half ass of them all. My halfiest ass, if you will. I never bothered to look at what Ordoemacs actually did before I set out to write “Ordovim”. Let’s look at them one at a time.

the only place it exists in its plain, readable form is in the pixels on the screen, and in the volatile RAM of the computer

Yeah, no. My “Ordovim” actually writes to disc first before encrypting and deleting the old plaintext file (which can easily be recovered).

coupled to a screensaver

Nope.

uses the little built-in CCD camera in the laptop to check to see if you are actually there

Nada.

blank the display and freeze the machine until such time as you type in a password, or biometrically verify your identity through voice recognition.

Nopity nopity nope.

“Ordovim”, besides the fact that it does encryption, isn’t even in the same galaxy as Ordoemacs.

So what was the takeaway here? Some of the things I learned at the end of this ordeal, which should be obvious to anyone with three quarters of a brain:

  • Don’t half ass things, because half asses multiply (I’m at sixteenth ass now).
  • Read the spec or you end up with “Ordovim”.
  • Invest a little bit of time to learning how to use and improve your skills with your tools (even if you think they are ‘stoopid’).
  • Kiddie fences are nice, but you have to grow up sometime.

Oh! And go read Neal Stephenson books.


You can find Ordovim here.