Inverse Cryptology

Author(s): Harold Lamkin
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n6 (Volume 2, Issue 6)
Date: June 1981
Pages: 3

This challenging code breaking game for 2 uses 4K ROM and 1K RAM. The computer encodes the secret phrase typed in by player 1. Player 2 guesses by typing letter=letter. A correct guess replaces the coded letter with the correct inverse letter.

DIM (25) stores the code. Subscripts 0 to 25 represent the real alphabet. The program recodes the phrase each time it prints it instead of storing a separate coded phrase. It’s slower but uses less memory.

Enter up to 1 line. To use up to 84 characters, delete line 425 and change line 410 to PRINT “ENTER LETTER=LETTER”. To exit, break the code or hit SHIFT BREAK quickly after a guess. To play again, hit RUN twice, then (NL).

  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$
Syntactic Sum=-7191

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