Code Protection Battle: 1980s Style! How to Turn BASIC Into a Fortress (or a Maze of Despair)

Ah, the 1980s. A time when hair was big, computers were small, and hackers weren’t breaking into the mainframe but rather into each other’s cassette tapes and floppy disks. Fast forward to today, and the Hacking Museum’s Retro CTF Challenge invites you to relive that glorious era of 8-bit mischief. Your mission? Protect your precious BASIC code from those devious rivals—or prove your worth by cracking theirs. Welcome to the Code Protection Battle, 1980s Style!

But how, you ask, does one secure a BASIC program on ancient hardware like the ZX81 or CPC 6128? Fear not! We’ve compiled a cheeky guide to some simple yet sneaky protection techniques you can employ, as well as a few ways hackers might try to weasel their way past them.


Protecting Your Code: The Retro Way

In the 1980s, protection wasn’t just about hiding your diary from your little brother; it was about making your friends sweat as they tried to break into your masterpiece. Here’s how you can do the same, using only the most devious, yet BASIC-friendly, tricks.

1. POKE Magic: Memory Manipulation for the Win!

Let’s face it, memory on the ZX81 is precious and limited. But you can still use a few POKE tricks to lock down your code like a digital Fort Knox.

  • Disable LIST Command: The easiest way to keep prying eyes out of your code is to disable the ability to list it. A simple POKE can make the LIST command useless, leaving hackers staring at a blank screen, wondering where they went wrong.
    Just remember: a clever hacker always finds a way around this, usually by POKE-ing your POKE back to life.

2. Self-Modifying Code: The Code That Erases Itself

Who needs enemies when your own code can betray you? Self-modifying code can change parts of the program at runtime, making it impossible for intruders to read or save your masterpiece intact.

  • Auto-Sabotage: Imagine a program that, if tampered with, deletes its own source. It’s like your code saying, “If I can’t have me, no one can!”

3. Obfuscation: The Art of Confusion

Make your code so unreadable that even you might have trouble understanding it after a week. Use complex expressions, nested calculations, and cryptic variable names. Remember, the goal is to make it as brain-melting as possible.

  • Example: Instead of using LET A = 10, try LET A = (2+3)*2. Sure, it does the same thing, but it’ll leave would-be hackers scratching their heads and questioning their life choices.

Creating a Bouncing or Scrolling Text Challenge

But let’s not forget the fun part: making your code entertaining, even if someone manages to break it. We’ve created two simple programs that draw graphics and animate text. They are vulnerable by design, ready for a fierce protection makeover.

ZX81 BASIC: Scrolling Text with a 3D Computer Graphic

The ZX81 isn’t exactly known for its graphical prowess, but that doesn’t mean we can’t get creative. This little gem creates a simple 3D computer using the ZX81’s ASCII graphics and animates a scrolling player name.

basicCopy code10 CLS: REM Clear the screen
20 PRINT AT 1,5;"  _______ ": REM Top of the monitor
30 PRINT AT 2,5;" /       /|": REM Side of the monitor
40 PRINT AT 3,5;"/_______/ |": REM Front of the monitor
50 PRINT AT 4,5;"|       | |": REM Front screen border
60 PRINT AT 5,5;"|       |/ ": REM Screen and side
70 PRINT AT 6,5;"|_______|  ": REM Bottom of the monitor
80 PRINT AT 7,5;"   ||||     ": REM Base of the monitor
90 PRINT AT 8,5;"   ||||     ": REM Stand
100 LET N$="Player1  ": REM Player name
110 LET L=LEN N$
120 FOR I=0 TO 31
130 PRINT AT 14,0; " ";: REM Erase the old text
140 FOR J=1 TO L
150 PRINT AT 14, 32-J;MID$(N$,J,1);: REM Display scrolling text
160 NEXT J
170 FOR K=1 TO 200: NEXT K: REM Short pause for smoother scrolling
180 LET N$=RIGHT$(N$,L-1)+LEFT$(N$,1): REM Rotate the text
190 GOTO 120: REM Loop forever
  • Objective for the Hacker: Replace "Player1" with their nickname, proving they’ve cracked the protection.

CPC 6128 BASIC: Bouncing Name with ASCII Art Computer

The CPC 6128 offers more graphical flair, perfect for creating a simple but impressive “3D computer” and a bouncing player name.

basicCopy code10 MODE 1: REM High-resolution 4-color mode
20 FOR I=10 TO 20: LOCATE I,5: PRINT CHR$(143); NEXT: REM Horizontal bar
30 LOCATE 8,3: PRINT "HACKING MUSEUM": REM Title
40 LOCATE 7,4: PRINT "RETRO CTF CHALLENGE": REM Subtitle
50 FOR I=12 TO 18
60 LOCATE 10,I: PRINT CHR$(143): REM Left vertical bar
70 LOCATE 30,I: PRINT CHR$(143): REM Right vertical bar
80 NEXT I
90 LOCATE 10,18: FOR I=10 TO 30: PRINT CHR$(143); NEXT: REM Bottom bar
100 N$="Player1": REM Player name
110 X=1: DIR=1: REM Initial position and direction
120 WHILE TRUE
130 LOCATE X,12: PRINT SPACE$(8);: REM Clear old text
140 LOCATE X,12: PRINT N$: REM Display player name
150 FOR I=1 TO 200: NEXT I: REM Short delay for animation
160 X=X+DIR: REM Update position
170 IF X<1 OR X>32 THEN DIR=-DIR: REM Reverse direction at edges
180 WEND: REM Infinite loop
  • Objective for the Hacker: Once they bypass the protection, they must replace "Player1" with their own nickname.

Future-Proofing Your Retro Defense

Sure, these techniques might seem rudimentary, but don’t underestimate the power of retro ingenuity. You’ll need to think like a 1980s hacker—because even back then, clever tricks were king. For added flair, consider combining multiple protections, like hiding code in unused memory or employing checksum verification. But remember: don’t make it so secure that even you can’t break back in!

So, retro warriors, sharpen your BASIC skills, fortify your code, and prepare to defend or attack in the Hacking Museum’s Retro CTF Challenge. Just remember, whether you’re the hero or the villain of this 8-bit story, the spirit of the 1980s lives on in every line of code you write… or crack.

Hints & Solutions: How to Protect Your BASIC Code from Being Listed

So, you’ve built your graphical BASIC masterpieces, and now you’re ready to protect them from snooping hackers who just can’t resist typing LIST to expose your brilliant work. Here are some hints and (semi-)devious methods to make sure your code stays hidden:


Hints for Protection:

  1. Memory Manipulation with POKE Commands
    • Use the ZX81 or CPC 6128’s memory locations to disable certain functionalities, like the LIST command. This makes it harder for hackers to inspect your code directly.
  2. Obfuscation and Redirection
    • Make your code confusing and misleading. Use decoy lines that don’t do much or mislead anyone trying to reverse-engineer your program. Redirect sections of your code to give the impression it’s doing something it’s not.
  3. Self-Modifying Code
    • Write code that changes itself after being loaded. This way, even if someone gets access to the original lines, they won’t be able to fully understand or save the modified version.
  4. Checksum Validation
    • Add a routine that checks if your code has been tampered with and causes the program to malfunction if it detects any changes. It won’t directly prevent LIST, but it’ll frustrate anyone trying to modify your program.

Basic Solutions to Disable LIST Command:

Here are some tricks you can use to block or interfere with the LIST command:

1. Using POKE to Disable LIST (ZX81 Example)

  • On the ZX81, you can use the POKE command to manipulate memory and disable the LIST command. A common address for this trick is 16509.
basicCopy code10 POKE 16509, 0: REM Disable LIST command
20 PRINT "Code Protected!"
30 REM Your main program here
40 GOTO 40: REM Infinite loop to keep the program running
  • What It Does: The POKE 16509, 0 command modifies a memory location responsible for handling the LIST command, effectively disabling it.

2. Disabling LIST on the CPC 6128

  • The Amstrad CPC 6128 allows for a more robust method of hiding your code using custom symbol tables or by manipulating firmware hooks.
basicCopy code10 SYMBOL AFTER 32: REM Prevents access to character symbols
20 FOR I = 0 TO 255: SYMBOL I, 255, 255, 255, 255, 255, 255, 255, 255: NEXT: REM Obscure characters
30 PRINT "Code Hidden from LIST!"
40 REM Your main program here
50 WHILE TRUE: WEND: REM Infinite loop to keep the program running
  • What It Does: This code alters the CPC’s symbol table, making characters appear as blank or solid blocks, preventing the code from being easily listed or read.

Bypassing the Protection (Hints for Hackers):

  1. Memory PEEK and POKE
    • If you’re on the attack, remember that you can always try to reverse POKE commands. For instance, on the ZX81, if POKE 16509, 0 disables LIST, you could try POKE 16509, 255 to re-enable it.
  2. Interrupting Auto-Run
    • Hold down key combinations like SHIFT + SPACE while loading the program to interrupt auto-run features and possibly access the code before protection mechanisms kick in.
  3. Using Emulators for Memory Dumps
    • Many modern ZX81 and CPC emulators come with memory inspection tools. Use these to dump memory and search for hidden parts of the code that may reveal obfuscation tricks or protection methods.

Remember, the fun of this challenge is in the game of cat and mouse between code protectors and crackers. Employ these techniques wisely, and may your BASIC creations remain secure… at least until a clever hacker comes along! Good luck, retro warriors!