Inverse Cryptology

Developer(s): Harold Lamkin
Date: 1981
Type: Program
Platform(s): ZX80
Tags: Game

A code-breaking game for two players on a 1K ZX80. Player 1 types a phrase, and the program prints it in a random substitution cipher. Player 2 guesses with coded letter = real letter; a right guess replaces that letter everywhere with its inverse-video original. Typing the whole phrase solves it, and the program reports the number of wrong guesses.

The cipher is never stored: the program re-encodes the phrase from a 26-element array each time it prints it, to save memory. Harold Lamkin sent a better way to exit the game to the July 1981 Dear Editor column.

Published in Syntax June 1981 (Inverse Cryptology).

Image Gallery

Source Code

  10 DIM A(25)
  20 RANDOMISE
  30 FOR Z=0 TO 25
  40 LET A(Z)=RND(26)+37
  60 FOR X=0 TO 25
  70 IF A(Z)=A(X) AND NOT Z=X THEN GO TO 40
  80 NEXT X
  90 NEXT Z
 100 PRINT "STATE A PHRASE"
 110 INPUT W$
 120 GO SUB 600
 400 PRINT
 410 PRINT "ENTER PHRASE OR LETTER=LETTER"
 420 INPUT U$
 425 IF U$=W$ THEN GO TO 900
 430 IF NOT CODE(TL$(U$))=227 THEN GO TO 700
 440 LET Y=CODE(TL$(TL$(U$)))
 450 IF Y<38 OR Y>63 THEN GO TO 700
 460 IF NOT A(Y-38)=CODE(U$) THEN GO TO 700
 470 LET A(Y-38)=Y+128
 480 CLS
 485 PRINT "CORRECT"
 490 GO SUB 600
 491 IF Z=0 THEN GO TO 900
 495 GO TO 400
 600 PRINT
 605 LET Z=0
 610 LET U$=W$
 620 LET Y=CODE(U$)
 630 IF Y<38 OR Y>63 THEN PRINT CHR$(Y);
 640 IF Y<38 OR Y>63 THEN GO TO 650
 645 PRINT CHR$(A(Y-38));
 646 IF NOT A(Y-38)=Y+128 THEN LET Z=Z+1
 650 IF Y=1 THEN GO TO 680
 660 LET U$=TL$(U$)
 670 GO TO 620
 680 PRINT
 690 RETURN
 700 LET X=X+1
 705 CLS
 710 PRINT "TRY AGAIN"
 720 GO SUB 600
 730 GO TO 400
 900 CLS
 910 PRINT "YOU BROKE THE CODE WITH ";X-26;" ERRORS ";W$

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