'Copyright 1999 The American Cryptogram Association (ACA) '3613 Piedmont Drive, Plano TX 75075-6234 'All rights reserved. 'Add 2 lines near top of MJ99 Code: Const PLUS=43,MINUS=45 Dim shared AUTO,INFOCOL '======= UPDATED ROUTINES =========== 'Replace 6 of the MJ99 routines with 'these updated ones of the same name. SUB DoFirstInits PERIODMAX=25: PERIODMIN=3: KEYR=5 BEGINC=3: COLINC=3: INFOCOL=58:PER=4 TYPE$="V" 'Demo from JA99 article CT$="BQYONIZIWQRGRIAQMQZVJTSUJKBPRM" CT$=CT$+"AGJLGKNAFRQCGLTVZHYPBG" END SUB 'DoFirstInits SUB ProcessKey(Ky,Ky$) Select Case Ky Case ASC("A") to ASC("Z"): SetKeyLetter(Ky$) Case ASC("a") to ASC("z"): SetKeyLetter(UCase$(Ky$)) Case PLUS: ChangeCipherType Case MINUS: ChangeAutoKeyType Case LEFT : MoveCursorLeft Case RIGHT: MoveCursorRight Case DOWN : DecreaseKeyLetter Case UP : IncreaseKeyLetter Case PAGEUP: IncreasePeriod Case PAGEDOWN: DecreasePeriod Case Else End Select RCPrint KEYR,CCOL,"" END SUB 'ProcessKey SUB DecColToScr(Row,KLtr$,CiCol) C = CiToScrCol(CiCol) EndRow = RowsInBlock(CiCol)+Row-1 CountR = RowsInBlock(1)+1 Posn = CiCol K$ = KLtr$ 'Local copy of key ltr Color 2 'Block color = green For R=Row To EndRow Ch$=Mid$(CT$,Posn,1) Posn=Posn+PER D$=Dec$(Ch$,K$) RCPrint R,C,D$ If AUTO=1 THEN K$=D$ Next R Color 7 'Default color = white DecColStats KLtr$,CiCol,Hi,Lo END SUB 'DecColToScr SUB MoveCursorLeft CCOL=CCOL-COLINC If CCOLCOLE Then CCOL=COLB ShowColKeyStats ScrToCiCol(CCOL) RCPrint CROW,CCOL,"" END SUB 'MoveCursorRight SUB InitDisplay Cls: CTLEN = LEN(CT$) KEY$=STRING$(PER,"A") BEGINR = KEYR+1 For Col=1 to PER DecColToScr BEGINR,"A",Col Next Col CCOL=CiToScrCol(1) : CROW=KEYR For I=1 to PER RCPrint KEYR,CiToScrCol(I),"A" Next I COLB=CCOL: COLE=COLB+COLINC*(PER-1) ShowColKeyStats 1 ShowAvgIndexOfCoin ShowCipherType RCPrint KEYR,CCOL,"" END SUB 'InitDisplay '======= NEW ROUTINES: Add ========== 'the routines below to the MJ99 code: SUB ShowCipherType C = InfoCol Select Case Type$ Case "V": RCPrint 2,C,"Vigenere" Case "B": RCPrint 2,C,"Beaufort" Case "A": RCPrint 2,C,"Variant " Case Else: RCPrint 2,C,"Porta " End Select RCPrint 1,C," " If Auto=1 Then RCPrint 1,C,"AutoKey" END SUB 'ShowCipherType SUB ChangeCipherType T=1+(Instr("VBAP",Type$)Mod 4) Type$=Mid$("VBAP",T,1) InitDisplay END SUB 'ChangeCipherType SUB ChangeAutoKeyType Auto = Auto Xor 1 InitDisplay END SUB 'ChangeAutoKeyType Function RJust$(I,N) 'Right Justify I Temp$=Space$(N)+Ltrim$(Str$(I)) RJust$=Right$(Temp$,N) End Function 'RJust$ SUB ShowColKeyStats(CiCol) For Kltr=0 to 25 C=2+2*Kltr : KLtr$=Chr$(KLtr+65) DecColStats Kltr$,CiCol,Hi,Lo RCPrint 1,C+1,KLtr$ RCPrint 2,C,RJust$(Lo,2) RCPrint 3,C,RJust$(Hi,2) Next Kltr END SUB 'ShowColKeyStats SUB DecColStats(Kltr$,CiCol,Hi,Lo) EndRow=RowsInBlock(CiCol) Posn = CiCol : K$ = Kltr$ Hi = 0 : Lo=0 For R=1 to EndRow Ch$=Mid$(CT$,Posn,1) Posn=Posn+PER D$=Dec$(Ch$,K$) If Instr("ETAONIRS",D$) Then Hi = Hi+1 Elseif Instr("JKQXZ",D$) Then Lo = Lo+1 End If If AUTO=1 THEN K$=D$ Next R END SUB 'DecColStats SUB SetKeyLetter(K$) Col= ScrToCiCol(CCOL) Mid$(KEY$,Col,1)=UCase$(K$) DecColToScr BEGINR,K$,Col RCPrint CROW,CiToScrCol(Col),K$ END SUB 'SetKeyLetter FUNCTION ColIndexOfCoin(Col) DIM Fr%(26) For I%=Col to CTLEN STEP PER Ch%=ASC(Mid$(CT$,I%,1))-ASC("@") Fr%(Ch%)=Fr%(Ch%)+1 N% = N%+1 Next I% For I%=1 to 26 Sum = Sum + Fr%(I%)*(Fr%(I%)-1) Next I% ColIndexOfCoin=Sum/(N%*(N%-1))*1000 END SUB 'ColIndexOfCoin SUB ShowAvgIndexOfCoin If auto=1 Then 'Skip if AutoKey Else For C=1 to Per Sum = Sum+ColIndexOfCoin(C) Next C Avg = Sum\Per Avg$="Period="+RJust$(Per,2) Avg$=Avg$+" AvgIC="+RJust$(Avg,3) RCPRINT 3,InfoCol,Avg$ End If END SUB 'ShowAvgIndexOfCoin