Making and breaking Ciphers on the Commodore 64 Part 11 - One time pads on a Commodore 64, probably a bad idea

Making and breaking Ciphers on the Commodore 64 Part 11 - One time pads on a Commodore 64, probably a bad idea

A while ago, I explained in detail how to generate one time pad sheets and use them to encrypt and decrypt messages.

It turned out to be doable, only requiring a pencil and a way to create random numbers, but it's slow, error prone and tedious.


The one time pad article was born out of my annual reading of Cryptonomicon. I wanted to learn how to make these pads, which if used correctly are mathematically unbreakable. I figured 3 or 5 other people might read it and learn how to make them too.

4 people read it, so my math is spot on!

The Rules

The Commodore version is just a weird side project. It violates the rules and is probably not great at making real random pads at all.

BUT it does look cool. So let's do it!


The program itself is pretty simple. There are 3 main functions:

  1. OTP Pad Sheet Generator
  2. Encrypt
  3. Decrypt

When creating this, we should go out of our way to keep from saving any of this information. The pads are unbreakable as long as a strict protocol is followed.

Let's run though using it one time. Pressing O will give you a fresh random pad sheet.

This is the set of codes we'll use for this article. Remember to never reuse these

This is not saved anywhere, so you either need to write this down or print it. There is no built in print function to the program, I use the screen printer in my Super Snapshot cartridge:

Cheating? Maybe.

In action

The steps are simple, but tedious. A price worth paying for security? Maybe.

Review the full article for all the details.

I never got around to implementing the translation from ASCII codes back to text. But in uppercase this is pretty trivial anyway. The table is:

Mistakes were made

I finished this program months ago and have been working every day to continue learning. After just a few months, I can already see MANY areas for improvement in this code.

What needed to be solved

This was very early on in my assembly adventures, which started in earnest in Sept of 2020. Assembly felt awkward and foreign. Some things that seemed like black magic then now seem simple and obvious.

We need to solve a couple problems and the rest is pretty easy:

This proved to not be terrible. In the addition, if the result was > 9, subtract 10. The reverse operation applies to the subtraction.

The last thing was the part I had the most fun with. I wanted to "wipe" the memory. On a Commodore 64, this is a silly exercise because simply turning off the Computer does a pretty good job at this.

This whole program is just for fun. So I clear the screen, then write the memory with garbage 20 times and call the reset vector. Silly, but fun.

Release it!?!?!

Nope. It violates the rules and the last thing I want to promote is the improper use of what is close to a perfect encryption scheme by letting people cheat on the process with a TERRIBLE Commodore program.

This was just a fun project for myself. You'll have to cheat on your own ;-)

I dare you.