A Silly Little Code Hack For The ZX81


Code Searcher is a simple number scanner for the ZX81. Enter in any four digits to see how long it takes, or don’t and see what happens.

I have some sort of fascination with code breaking. A byproduct of all the spy movies I watched as a kid. A friend of my would make spy cases with Lego’s, and I had to build my own of course. I had a wallet with home made credentials and so on. Code Searcher is a bit of a homage to those golden age gadgets of the 60s and 70s.

Not quite as bulky spy gadget.

Given the ZX81 is quite a small and sleek device, it would fit in with most movie gadgets of the era. That aside, my program is quite short, consisting of few visual elements. You enter in a number “word” to start. The word must be at least 4 digits—letters aren’t allowed. Once you enter it, the computer spins up to find your code.

Code Searcher, 1984, ZX81 screenshot by Steven ReidCode Searcher, 1984, ZX81 screenshot by Steven Reid

The code finding is quick, scrolling the screen as it finds each number. The display reminds me of the key code finders you see a secret agent attach to some card reader. Like those gadgets, it displays the number each time it finds one.

Code Searcher does much the same, using a scroll to display each new digit found. I could see myself playing a spy and using my ZX81 to crack into some secret base. Although I did use my ZX81 for some games, I don’t remember actually remember using this program. It’s a shame too, as it would have been fun.

Now, you can also be a bit evil. If you had a friend enter the code, they could cheat and enter letters or not enough digits. The program doesn’t verify your input. Instead, it will fail with a childish error. Give it a try and see.

Not quite hacking anything.

As fun as the program it, is doesn’t actually break any codes. More of a game, the program uses a couple of loops to figure out the code. Code Searcher is more of brute force display than hacking anything.

Part of the reason you enter the code as a string is how it searches. Instead of using numbers, the test is against an array of digits. The loops are two index: one to the number of digits in the code, and one is the size of the digit array. For each digit, it searches the given string for numbers. If it finds one, replaces the digit in the display string.

I did make a minor fix to the display routine. The program as written didn’t display the final code it found. To fix that, I added two lines to display the final contents of B$. This is only noticeable if you have a 9 in your word.

Thinking about what to change.

In a way, the program is quite scalable. With a few simple changes, you can add more digits or even letters to the display. Thinking about changes, it wouldn’t be hard to make it a hex code for example. You would need to add “ABCDEF” to K$ and increase the A loop to 16.

Speaking of the A loop, it is a bit overkill. Code Searcher will always run through all the digits, even if it has found the code. This keeps the search routine fast, since it doesn’t have to run another test. But, it prints more lines than needed. The ZX81 doesn’t have a while loop, but it wouldn’t be hard to emulate one. Can you do that?

Adding more digits in the code is a bit more work. You’d have to change the size of A$, update B$ with more periods, and adjust the B loop. As a coding exercise, make the program adjust the code size based on a variable.

Although the scrolling mechanism works, it isn’t quite the same as the movies. Given this is a demo program, using a random number and a graphic display would be more showy. It wouldn’t be hard to create some animations for the digits as the computer figured out the code. Alas, an exercise for another time.

For extra credit, can you make a version that let’s the user enter the code but doesn’t require the INPUT? Maybe a version that hides the digits after they type them? You could also get sophisticated and let them correct or clear the code, or force them to verify it. Have fun with this one!



Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive