Code Breaker (Cryptograms)

Developer(s): Pete Cooke
Date: 1985
Type: Program
Platform(s): TS 2068
Tags: Game

Code Breaker is a cryptogram game. You pick one of six passages, which is enciphered with a new random letter substitution each time. The cipher text is shown in capitals with your current decoding in lower case above each line, and below it are a bar chart of how often each cipher letter occurs and the table mapping A–Z to a–z. You change the mapping by typing a cipher letter and the letter it should become, then ENTER; DELETE corrects an entry and 1 quits the puzzle. When the text is fully decoded, the program announces “RIGHT… WELL DONE”. I on the menu shows the instructions and Q stops.

The REMs read “CODEBREAKER” and “Pete Cooke Mar 85”. Pete Cooke was a British author of tape and magazine games. This is a different program from the Mastermind-style Codebreaker on the site. It was on the disk SNUG_11_12 as C. Break with the machine code C. break C (1500 bytes at 30000), which holds the six passages and the display and checking routines.

Program Analysis

Structure

  • Line 490: the loader. It sets CLEAR 29939, loads the code and runs the program.
  • Lines 25–110: set up the UDGs, draw the title and menu, and read the choice.
  • Lines 120–240: one puzzle. It shuffles a key, displays the text, and loops taking letter swaps until the text is solved or abandoned.
  • Lines 250–280: the success message. Lines 290–340: instructions.
  • Lines 350–440: the From/To entry routine. Lines 450–480: “PRESS SPACE”.
  • Lines 9910–9950: point the UDGs at the data in a REM.

Working Memory

BASIC and the machine code share a small table below the code. The 26 bytes from 29940 hold the random key, shuffled in lines 150–170 by drawing letters one at a time from a string of all 26. The 26 bytes from 29970 hold the player’s map, reset to identity in line 130 and changed by POKE (29970+FROM),TO. Byte 29999 holds the passage number. USR 30000 draws the puzzle screen and USR 30003 returns 0 when the map undoes the key.

Notable Techniques

  • Line 9940 sets the UDG system variable (23675–23676) to point into the REM of line 9950, found through NXTLIN, so the title lettering needs no POKE loop. UDGs j–q spell CODEBREAKER and r–u are the corners of its frame.
  • DEF FN h and DEF FN l split an address into high and low bytes.
  • The success routine alternates OUT 254,22 and OUT 254,6. Bit 4 of port 254 drives the speaker, so this buzzes while the border stays yellow.
  • Numbers are written as SGN PI, NOT PI and VAL "300" to save memory.

Potential Issues

  • Q stops the program with CLEAR 65367, but the UDG pointer is left inside the REM, so UDGs show the REM’s bytes until it is reset.

This program came from an Oliger (JLO SAFE) disk and was converted to load from tape by making the disk LOAD / and SAVE / commands in lines 490 and 500 plain tape commands. The machine code is unchanged. It was tested in ZEsarUX on a stock TS2068 through the menu, the first puzzle with its frequency chart and one letter swap.

Image Gallery

Source Code

   10 REM   CODEBREAKER 
   20 REM Pete Cooke Mar 85
   25 DEF FN h(x)=INT (x/256): DEF FN l(x)=x-256*FN h(x): GO SUB 9910
   30 POKE 23658,8: PAPER 7: INK 0: BORDER 6: CLS 
   40 PRINT ''"        r''''''''''''''''''''''''''s"'"        :  jklmnompqmo  :"'"        t..........................u"
   50 PRINT ''"  PRESS..."
   60 FOR N=SGN PI TO 6: PRINT AT 8+N,2;N;". FOR TEXT ";N: NEXT N: PRINT '"  I FOR INSTRUCTIONS"''"  Q TO STOP "
   70 LET Z$=INKEY$: IF (Z$<"1" OR Z$>"6") AND Z$<>"I" AND Z$<>"Q" THEN GO TO 70
   80 IF Z$="Q" OR Z$="q" THEN CLEAR 65367: STOP 
   90 IF Z$="I" THEN GO SUB 290: GO TO 30
  100 POKE 29999,VAL Z$-1
  110 GO SUB 120: GO TO 30
  120 CLS : PRINT PAPER 6;"         jklmnompqmo   (1=quit) "
  130 FOR N=0 TO 25: POKE (29970+N),N: NEXT N
  140 LET A$="": FOR N=0 TO 25: LET A$=A$+CHR$ N: NEXT N
  150 FOR N=0 TO 25: LET R=INT (1+RND*LEN A$)
  160 POKE 29940+N,CODE A$(R): LET A$=A$( TO R-1)+A$(R+1 TO )
  170 NEXT N
  180 PRINT : LET V=USR VAL "30000"
  190 PRINT AT 21,NOT PI;"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  200 PRINT : IF USR 30003=0 THEN GO TO 250
  210 GO SUB 350: IF QUIT=1 THEN GO SUB 450: RETURN 
  220 LET FROM=CODE A$(1)-65: LET TO=CODE A$(2)-65
  230 POKE (29970+FROM),TO
  240 GO TO 200
  250 INPUT ;: PRINT #1;AT 1,0; PAPER 2; INK 7;"      RIGHT...  WELL DONE",
  260 FOR N=PI TO VAL "300": NEXT N
  270 PRINT AT 2,0;: FOR N=0 TO 7: FOR M=0 TO 31: PRINT " ";: OUT 254,16+6: OUT 254,6: NEXT M: PRINT '': NEXT N
  280 INPUT ;: GO SUB 450: RETURN 
  290 CLS : PRINT "        INSTRUCTIONS."
  300 PRINT '"  This program will display a"'"piece of encoded text in "'"capital letters."
  310 PRINT '"  Above this is the same text"'"in lower case letters and below"'"that a table showing how the"'"upper case letters are mapped"'"onto the lower case and a"'"frequency count for the upper"'"case letters."
  320 PRINT '"  You must alter the map by"'"giving the computer an upper"'"case letter, and which lower"'"letter you wish to alter it to."
  330 PRINT '"  The program will tell you when"'"you have decoded the text"'"correctly."
  340 GO SUB 450: CLS : RETURN 
  350 LET QUIT=0: LET A$=""
  360 PRINT #1;AT 1,0;"From ";: IF LEN a$>0 THEN PRINT #1;a$(1);" to ";: IF LEN a$>1 THEN PRINT #1;a$(2);
  370 PRINT #1;"       ";
  380 IF INKEY$<>"" THEN GO TO 380
  390 LET Z$=INKEY$: IF Z$="" THEN GO TO 390
  400 IF Z$="1" THEN LET QUIT=1: RETURN 
  410 IF Z$>="A" AND Z$<="Z" AND LEN A$<=1 THEN LET A$=A$+Z$
  420 IF Z$=CHR$ 12 AND A$<>"" THEN LET A$=A$( TO LEN A$-1)
  430 IF z$<>CHR$ 13 OR LEN a$<>2 THEN GO TO 360
  440 RETURN 
  450 INPUT ;: PRINT #1;AT 1,10;"PRESS SPACE"
  460 IF INKEY$<>"" THEN GO TO 460
  470 IF INKEY$<>" " THEN GO TO 470
  480 INPUT ;: RETURN 
  490 CLEAR 29939: LOAD "C. break C"CODE : RUN 
  500 CLEAR : SAVE "C. Break" LINE 490: SAVE "C. break C"CODE 30000,1500: STOP 
 9910 REM POKE UDGs
 9940 LET x=VAL "(PEEK 23637+PEEK 23638*256)+6": POKE 23675,FN l(x): POKE 23676,FN h(x): RETURN 
 9950 REM  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<f``f<<ffff<|ffff|~`|``~|f|ff||f|fff<f~fffffxfff?* COPY SAVE LIST LIST LIST SAVE DRAW RETURN COPY LIST LIST LIST SAVE COPY *? COPY RETURN DRAW SAVE INPUT . &$?k,A

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.