10 '*** RAILF.ENC *** Railfence encipherer MB Feb 90 20 KEY OFF:CLEAR:DEFINT A-Z 30 GOTO 9500 100 ' --- now for the Railfence --- 110 LOCATE 13,1:INPUT "How many rails? (ACA std is 3-7): ", NR 120 IF NR=0 THEN NR=XNR:LOCATE 13,34:PRINT NR 130 : 140 LOCATE 16,1:PRINT "(Offset of"NR-1"will give "CHR$(34)"W"CHR$(34)" format railfence)" 150 LOCATE 15,1:PRINT "What is the offset of the first letter? (0-";2*NR-2;"): ";:INPUT OS 160 IF OS=0 THEN OS=XOS: LOCATE 15,49:PRINT OS 170 P$=STRING$(OS," ")+P$ 'add offset blanks to start of text 180 LOCATE 18,1:PRINT"Is this to be a Redefence cipher? (Y/N*): ";:LINE INPUT Q$:IF Q$="Y" OR Q$="y" THEN GOSUB 700:GOTO 198 190 FOR N=1 TO NR:SEQ(N)=N:NEXT 'this is RAILFENCE rail sequence 198 LOCATE 18,1:PRINT SPC(79):LOCATE 18,1:COLOR 0,7:PRINT" Ciphertext is: ":COLOR 7,0 199 : 200 ' --- calculate number of blocks = # of sawteeth --- 210 LP=LEN(P$) 'length of offset+ptext 220 NB=INT(LP/NR) 'NB is # of blocks 230 LB=2*(NR-1) 'LB is length of a block 240 FOR N=1 TO NB 250 BLOCK$(N)=MID$(P$,1+(N-1)*LB,LB) 'break up the pt into blocks 260 NEXT 290 : 300 ' --- add contribution from each block to rail total --- 310 FOR M=1 TO NB 'for each block 320 R$(1,M) =MID$(BLOCK$(M),1,1) 330 R$(NR,M)=MID$(BLOCK$(M),NR,1) 340 FOR J=2 TO NR-1 350 R$(J,M)=MID$(BLOCK$(M),J,1)+MID$(BLOCK$(M),2*NR-J,1) 360 NEXT J 370 NEXT M 390 : 400 ' --- add block contributions together to form ciphertext --- 410 FOR M=1 TO NR 420 FOR J=1 TO NB 430 RAIL$(SEQ(M))=RAIL$(SEQ(M))+R$(SEQ(M),J) 440 NEXT J 450 CT$=CT$+RAIL$(SEQ(M)) 460 NEXT M 490 : 500 ' --- and print as ciphertext --- 510 X$=CT$:CT$="":FOR N=1 TO LEN(X$) 520 IF MID$(X$,N,1)=" " THEN GOTO 530 ELSE CT$=CT$+MID$(X$,N,1) 530 NEXT 540 FOR N=1 TO LP 550 PRINT MID$(CT$,N,1);:OP$=OP$+MID$(CT$,N,1) 560 IF N/5=INT(N/5) THEN PRINT " ";:OP$=OP$+" " 570 NEXT:GOTO 9260 600 : 700 ' --- get redefence rail sequence --- 710 LOCATE 1,1:PRINT DATE$ TAB(28)"* REDEFENCE ENCIPHERMENT *" :PRINT TAB(30)STRING$(22,"-"):TYPE$="REDEFENCE" 720 LOCATE 18,1:PRINT SPC(79) 730 LOCATE 18,1:PRINT "What is the rail sequence?":PRINT "(Separate each number by a comma, eg 2,1,3. to end): ":LOCATE 18,28:LINE INPUT SEQ$ 740 IF LEN(SEQ$)=0 THEN SEQ$=XSEQ$:LOCATE 18,28:PRINT SEQ$ 745 LOCATE 18,1:PRINT SPC(79):PRINT SPC(79):LOCATE 18,1:PRINT "REDEFENCE sequence is:" 750 IF LEN(SEQ$)<>2*NR-1 THEN PRINT"I was expecting a total of"2*NR-1"letters and commas. Try again.":GOSUB 5020: LOCATE 19,1:PRINT SPC(79):GOTO 710 760 LOCATE 18,1:PRINT SPC(79):PRINT SPC(79):LOCATE 18,1:PRINT "REDEFENCE sequence is:" 770 FOR N=1 TO NR 780 SEQ(N)=VAL(MID$(SEQ$,1+(N-1)*2,1)) 790 PRINT SEQ(N); 800 NEXT 810 GOSUB 5020 820 LOCATE 1,62:PRINT "Seq: "SEQ$; 830 RETURN 5000 ' --- misc subs --- 5010 CLS:PRINT DATE$ TAB(28)"* RAILFENCE ENCIPHERMENT *" :PRINT TAB(30)STRING$(22,"-"):RETURN 5020 LOCATE 23,1:PRINT SPC(79);:LOCATE 23,28:PRINT "Press to proceed: ";:LINE INPUT Q$:LOCATE 23,1:PRINT SPC(79);:RETURN 5100 LOCATE 23,1:PRINT SPC(79):LOCATE 23,39:PRINT "end":LOCATE 23,1:END 9250 ' --- ENCPRT.STD --- 9260 LOCATE 23,1:PRINT"Do you wish to rint this for the Cm, do nother, or uit? ";:LINE INPUT Q$ 9270 ON INSTR("PpAaQq",Q$)GOTO 9280,9280,10,10,5100,5100:GOTO 9260 9280 ON ERROR GOTO 18000 9290 WIDTH "lpt1:",255 'needed by GWBASIC 9300 EM(0)=-12971:EM(1)=23813:EM(2)=-28469 9310 X=VARPTR(EM(0)) 9320 CALL X 9340 FOR N=1 TO 20:LPRINT:NEXT 'space to bottom of page 9350 LPRINT TYPE$;" encipherment by Mike Barlow "DATE$:LPRINT 9360 LPRINT OP$ 9370 ON ERROR GOTO 0 9380 LPRINT CHR$(12):GOTO 9260 9490 : 9500 ' --- start here --- 9510 TYPE$="RAILFENCE" 9520 GOSUB 5010 9530 PRINT:PRINT TAB(33)"By Mike Barlow" 9560 ' --- enter data --- 9610 GOSUB 20000 'pick up default example XPT$ 9620 LOCATE 7,1:PRINT"ENTER THE PLAIN TEXT (either case, with or w/o spaces, 240 chars max):" 9630 Y=CSRLIN:LINE INPUT PT$: IF PT$="" THEN PT$=XPT$:LOCATE Y,1:PRINT PT$ 9640 NC=LEN(PT$):FOR N=1 TO NC:IF MID$(PT$,N,1)=" " THEN 9650 ELSE P$=P$+CHR$(ASC(MID$(PT$,N,1)) AND 223) 'remove spaces and force UC 9650 NEXT:NR=LEN(P$) 9660 PRINT:PRINT"With spaces removed, there are"NR"characters in the text:":PRINT P$ 9790 GOSUB 5020:GOTO 100 9798 : 18000 ' --- printer error trap --- 18010 IF ERR=24 OR ERR=25 OR ERR=27 THEN LOCATE 23,1:PRINT SPC(79):LOCATE 23,15: PRINT "Printer not ready; press to proceed: ";:LINE INPUT Q$:LOCATE 23,1:PRINT SPC(79):RESUME 18020 ON ERROR GOTO 0:STOP 20000 ' ---- examples ---- 20010 XPT$="Civil War field cipher": XNR=3: XOS=0 'ACA&U p48 20020 XSEQ$="2,1,3" 'REDEFENCE sequence 20100 RETURN 60000 ' mod record; Feb 17 90 op$ added to lines 550/560 for correct SCRYER printout 65000 SAVE"railf.enc",A