One-time pad in Javascript


Recently, I was doing some research on encryption for a project. I’ve used encryption libraries in past projects, but I’ve never written any actual encryption algorithms myself. And as the Internet does from time to time, I got sucked into looking around at the various algorithms. I came across an interesting encryption algorithm that I had never heard of. Apparently, it can not be cracked: the one-time pad.

This is the one that most movies reference when you see the spy guy with his little flip book of paper. He’d write down some random numbers he heard off the radio, or what have you, then burn up the page. It’s an incredibly simple algorithm, and that makes it very useful because you don’t even need a computer to do the encryption / decryption.

For fun I slapped together one in javascript just to have a play with writing an encryption algorithm (probably the simplest on the planet). The javascript version does most of the ascii set instead of just A-Z.

It’s mostly useless, but it was a fun little exercise and a neat little view into history.