Crypto (Syntax)

Developer(s): Imre Auersbacher
Date: 1984
Type: Program
Platform(s): ZX81, TS 1000

A cipher program. Answer C to encode or D to decode, type the keyword (the screen shows CENSORED instead), and enter the message. The program shifts each character by the matching letter of the keyword, repeating the keyword as needed, and prints the result. Decoding with the same keyword gives back the original message; the wrong keyword gives nonsense.

Keyword and message can be any length and may use letters, digits, spaces and the symbols .,:;$<>()+-=?*, but not graphics characters. The keyword is cleared at the end of each run. The article suggests using it as a subroutine to protect data files.

Published in Syntax September 1984 (Crypto).

Related Articles

This sophisticated coder and decoder runs in only 2K. Use it for fun as a stand-alone program, or create a subroutine to make your datafiles unintelligible without the keyword.

Image Gallery

Source Code

   5 FAST
  10 PRINT "CIPHER/DECIPHER? C/D";
  15 INPUT Q$
  16 PRINT Q$
  18 PRINT
  20 PRINT "KEYWORD:";
  30 INPUT Y$
  40 PRINT "CENSORED"
  42 PRINT
  45 DIM Z(LEN Y$)
  50 FOR Z=1 TO LEN Y$
  60 LET Z(Z)=CODE Y$(Z)-13
  70 IF Z(Z)<0 THEN LET Z(Z)=51
 110 NEXT Z
 200 PRINT "ENTER MESSAGE:"
 210 INPUT M$
 220 PRINT M$
 230 PRINT
 260 IF Q$(1)="D" THEN GOTO 400
 300 PRINT "CIPHER -->"
 305 LET Y=1
 310 FOR Z=1 TO LEN M$
 315 IF Y>LEN Y$ THEN LET Y=1
 320 LET T=CODE M$(Z)
 325 LET X=Z(Y)+T+9
 328 IF T=0 THEN LET X=X+64
 330 LET X=X-51*INT (X/51)+13
 332 IF X=63 THEN LET X=-1
 334 PRINT CHR$ (X+1);
 335 LET Y=Y+1
 340 NEXT Z
 350 GOTO 500
 400 PRINT "DECODED -->"
 410 LET Y=1
 420 FOR Z=1 TO LEN M$
 430 IF Y>LEN Y$ THEN LET Y=1
 435 LET T=CODE M$(Z)
 440 LET X=T-Z(Y)-24
 445 IF T=0 THEN LET X=X+64
 450 IF X>=13 THEN GOTO 460
 454 LET X=X+51
 456 GOTO 450
 460 IF X=63 THEN LET X=-1
 465 PRINT CHR$ (X+1);
 470 LET Y=Y+1
 480 NEXT Z
 500 CLEAR

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