Hiding Basic Code

By Mark Bellis

Originally published in EUG #37

Having looked at games such as Clogger, I have found that sometimes a BASIC program is hidden, so you can't easily copy or hack it.

The technique used in Clogger is as follows:

Characters 3 (printer off), 12 (CLS), 15 (page mode off) and 21 (VDU off) are inserted in REM statements to prevent you from looking at the listing or printing it.

I have written a demo using VDU21 and VDU6 to illustrate it.

The program will only list as one line - a REM statement containing a message - but the program is much longer. When RUN, it will produce a familiar pattern.

I have not put many tricky characters in to allow you to look at how it works. Try "LIST 20," to see a few more lines, then LIST xxx, with xxx as the multiple of 10 after the last printed line.

Notice how the REM statements take off the first word each time.

How To Produce The Effect

Write a simple program, such as:

         10REM* Demo@
         20PRINT"Hello world"
         30REM* program.
Be careful to put the *s, @s and spaces in the right places in the REM statements. Then add the following lines:
        100FOR I = PAGE TO TOP
        110IF ?I = 42 THEN ?I = 6         ) Change *s to CHR$6
        120IF ?I = 64 THEN ?I = 21        ) Change @s to CHR$21
        130NEXT I
Type GOTO 100 and lines 20 and 30 will now be hidden.

Following the deletion of lines 100-130, the program will appear as one line.

Be careful to use an alternative to the * and @ if you them elsewhere in your programs, and don't use any line numbers where (number MOD 256) is equal to the ASC code of the characters you're using (eg 320 is 01 40 in hex, as 256 + 64 = 320).

The way I wrote the demo program was to enter the REM lines first and hide them as above, then RENUMBER them as multiples of 100 with RENUMBER 100,100 and I entered the rest of the program as the other multiples of 10 (with a few extras), spliting it fairly evenly between the REM statements, so as to even out the time taken between the printing of each word of the whole message, in order that the uninitiated user might not notice the effect.

For long programs, you will need more REM lines, so that the time between words is kept to a minimum.

I suppose the authors of Clogger had a program such as this:

         10 REM****CLOGGER.
         20 REM****by Me.
         30 REM****written whenever.
         40 REM****:MODE 5
         50 REM****:VDU23,8202;0;0;0;
            etc...
      10000 FOR I = PAGE TO TOP
      10010 IF !I = &2A2A2A2A THEN !I = &150F030C
      10020 NEXT I
Line 10010 replaces **** with 12, 3, 15, 21 which will clear the screen (and eject the printer paper), turn off the printer, turn off page mode and turn off VDU output when you list the program.

I think the authors actually put REM statements about every fourth line, but after a *DUMP Clogger 0 E00, and seeing the codes in the program, I wrote something like the reverse of line 10010 above to reveal the code.

Tip: It is easier to use a block of *s for the replacement characters so that lines such as 810 (3*256+42, or 03 2A hex) are not corrupted by the replacement code.

Mark Bellis, EUG #37