Classic Computer Magazine Archive COMPUTE! ISSUE 76 / SEPTEMBER 1986 / PAGE 59

64 Encryptor

James Pettus

This BASIC utility will hide your programs from prying eyes. It encrypts a BASIC program in memory so that it can be neither stopped while running nor listed. The program also includes an option for restoring things back to normal if you wish. A secret ID code even prevents people who have the Encryptor program themselves from unlocking your secrets.

Part of the fun of computing is sharing one of your programs with others. At times, however, you may want to keep things confidential. For example, you might have written a finance program which contains DATA statements revealing your entire personal portfolio. You might want to prevent others from looking at this information. The LIST command ordinarily displays the contents of any BASIC program.

However, you can use "64 Encryptor" to encrypt any BASIC program to prevent other people from deciphering it. Though the encrypted program can't be listed or examined, it still runs normally. And since each copy of Encryptor has a unique ID code, your protected program should be safe even from others who have 64 Encryptor themselves.

A Special Random Identifier

Type in and save the BASIC loader program listed below. You may save it with any filename you like, except ENCRYPTOR (that's what the BASIC loader will name the machine language file that it creates). When the program runs, it spends a few seconds creating the Encryptor machine language routine in the memory area starting at 49152, then it saves the machine language to disk. To have the Encryptor file saved to tape instead, change the DV=8 in line 80 to DV=1.

When the loader writes Encryptor into high memory, it embeds an identifier mark within the program. The identifier is randomly selected and will be different each time you run the loader. This feature makes a program encrypted with one copy of Encryptor incompatible with any other copy of Encryptor—even another copy created on the same 64. As a result, you don't have to worry that other people with this program can decrypt your programs.

To encrypt or decrypt a BASIC program, follow these steps:

  • Load Encryptor with LOAD "ENCRYPTOR",8,1 for disk or LOAD "ENCRYPTOR",1,1 for tape.
  • Type NEW and press RETURN.
  • Load the BASIC program you wish to encrypt or decrypt.
  • To encrypt a program, type SYS 49152 and press RETURN. When the cursor returns, be sure to immediately save a copy of the encrypted version using a different filename.
  • To decrypt a program, type SYS 49155 and press RETURN.

An encrypted program runs normally, but cannot easily be examined by the person using it. When you run an encrypted program, a built-in machine language subroutine is called to decrypt the actual program data and run it. At the same time, Encryptor disables the LIST command and the RUN/STOP-RESTORE key combination. You should make sure that the program being encrypted does not contain any references to the ROM routine at 65505 ($FFE1), which tests to see whether the RUN/STOP key has been pressed. The program to be protected also should not offer the user the option of exiting the program.

Because the BASIC loader program creates a different Encryptor each time it is run, you should take care to make a backup copy of each Encryptor that you create. (You should also keep an unprotected copy of any important programs you encrypt.) If you accidentally erase your only copy of Encryptor, you will not be able to decrypt any programs protected with that version. Of course, to keep your programs secure, you should not give anyone else a copy of your version of Encryptor.

Works With BASIC/Machine Language Combinations

Some BASIC programs require that you relocate the start of BASIC text before you load and run them, others leave little memory for variables (meaning you should not enlarge the program), and some BASIC programs cannot be relocated because they have ML routines appended to the end of BASIC text. Encryptor has been designed with all these conditions in mind. The ML routine included in an encrypted program contains no absolute addresses, and it moves program data down in memory after it has done its work, so nonrelocating BASIC programs can still be safely encrypted.

64 Encryptor

For instructions on entering this listing, please refer to "COMPUTE!'s Guide to Typing In Programs" in this issue of COMPUTE!.

GH 10 PRINT CHR$(147)CHR$(155)"PLEASE WAIT":I=49152
HG 20 READ A:IF A=256 THEN 40
JG 50 POKE I+4574,255
FQ 60 POKE I+4577,128:FOR A=I-317 TO I-308:POKE A,PEEK(I+4586):NEXT:POKE I+4577,0
DB 70 POKE I+4574,0
JM 100 POKE 251,0:POKE 252,192:POKE 780,251:POKE 782,I/256:POKE 781,I-PEEK(782)*256
EE 120 DATA 76,254,192,76,28,193,167,43
RH 130 DATA 135,251,135,253,167,44,135,254
EE 140 DATA 232,134,252,160,0,177,251,145
AF 150 DATA 253,230,251,230,253,208,4,230
KH 160 DATA 252,230,254,167,252,197,46,208
SQ 170 DATA 236,167,251,197,45,208,230,198
RF 180 DATA 46,96,167,44,135,175,167,43
AM 190 DATA 56,233,1,176,2,198,175,133
SF 200 DATA 174,167,46,135,252,232,134,254
AJ 210 DATA 167,45,56,233,1,176,4,198
GC 220 DATA 252,198,254,133,251,133,253,160
HC 230 DATA 0,177,251,145,253,198,251,198
GA 240 DATA 253,167,251,201,255,208,4,198
MB 250 DATA 252,198,254,167,252,197,175,208
KC 260 DATA 232,167,251,197,174,208,226,230
QH 270 DATA 46,96,167,43,135,251,167,44
RJ 280 DATA 232,134,252,160,0,162,8,177
FR 290 DATA 251,10,102,255,202,208,250,167
EQ 300 DATA 255,145,251,230,251,208,2,230
EQ 310 DATA 252,167,252,197,46,208,230,167
CD 320 DATA 251,197,45,208,224,96,169,0
CX 330 DATA 133,255,160,165,191,79,192,69
RC 340 DATA 255,133,255,209,43,208,6,200
PB 350 DATA 192,175,208,240,96,169,199,160
QX 360 DATA 192,32,30,171,108,2,160,69
KP 370 DATA 78,67,82,89,80,84,79,82
DQ 380 DATA 32,73,46,68,46,32,77,73
AK 390 DATA 83,77,65,84,67,72,0,169
DR 400 DATA 0,133,255,160,165,191,79,192
GM 410 DATA 69,255,133,255,145,43,200,192
CX 420 DATA 175,208,242,96,0,0,0,0
GC 430 DATA 0,0,0,0,0,0,32,50
JC 440 DATA 192,32,122,192,160,0,191,48
GG 450 DATA 193,145,43,200,208,248,32,223
QM 460 DATA 192,32,89,166,32,51,165,104
FD 470 DATA 104,108,2,160,32,166,192,32
EA 480 DATA 122,192,32,6,192,32,89,166
AC 490 DATA 32,51,165,104,104,108,2,160
RR 500 DATA 25,8,0,0,158,194,40,52
MS 510 DATA 51,41,170,50,53,54,172,194
JA 520 DATA 40,52,52,41,170,50,54,0
XF 530 DATA 0,0,167,43,135,251,167,44
BJ 540 DATA 232,134,252,160,0,162,8,177
FR 550 DATA 251,10,102,255,202,208,250,167
PR 560 DATA 255,145,251,230,251,208,2,230
HR 570 DATA 252,167,252,197,46,208,230,167
JR 580 DATA 251,197,45,208,224,160,84,177
MQ 590 DATA 43,153,172,1,200,192,165,208
AH 600 DATA 246,76,0,2,167,43,135,251
DP 610 DATA 135,253,167,44,135,254,232,134
RS 620 DATA 252,160,0,177,251,145,253,230
XB 630 DATA 251,230,253,208,4,230,252,230
PX 640 DATA 254,167,252,197,46,208,236,167
DF 650 DATA 251,197,45,208,230,198,46,32
PB 660 DATA 89,166,32,51,165,120,162,255
JJ 670 DATA 169,182,143,6,3,169,234,143
AG 680 DATA 40,3,169,246,143,41,3,169
FK 690 DATA 193,143,24,3,169,254,143,25
PG 700 DATA 3,88,76,174,167,0,0,0
RP 710 DATA 0,0,0,0,0,0,0,0
KM 720 DATA 0,0,0,0,0,0,0,0
FK 730 DATA 0,0,0,0,0,0,0,0
BJ 740 DATA 0,0,0,0,0,0,0,0
RJ 750 DATA 0,0,0,0,0,0,0,0
KX 760 DATA 0,0,0,0,0,0,0,0
FS 770 DATA 0,0,0,0,0,0,0,0
BR 780 DATA 0,0,0,0,0,0,0,0
RR 790 DATA 0,0,0,0,0,0,0,0
MR 800 DATA 0,0,0,0,0,0,0,0
GQ 810 DATA 0,0,0,0,0,0,0,0
HF 820 DATA 0,256