'FindKm.Bas 'Demo for MA01-MA2's alphabet Al$ = "QNKBMFEGJHXCTDUAZWPYRLSVOI" PrintKM Al$,4,10 'Print table of End 'decimation scores Sub PrintKM(Al$,N1,N2) 'PrintKM will Hdr$=Space$(26) 'print scores For N=N1 to N2 'for widths Hdr$=Hdr$+RJust$(N,5)'N1 to N2. Next N 'Loop builds header Print Hdr$ 'string which we print. For I=1 to 12 'For each of 12 A$=NextDec$(Al$) 'odd decimations Row$=A$ 'we build a row For N=N1 to N2 'of scores Row$=Row$+RJust$(KMScore(A$,N),5) Next N Print Row$ 'Print scores Next I 'next decimation End Sub 'PrintKM 'Returns next odd decimation of Al$ Function NextDec$(Al$) Static If Al$<>A$ Then 'If Al$ or A$ has A$=Al$ 'changed then start I=1 'with decimation 1 End If If I=13 Then I=15'Skip decimation 13 Count=0 : J=1 : Dec$="" While Count < 26 'Build next Dec$=Dec$+Mid$(A$,J,1)'decimation J= (J+I) mod 26 'one letter If J=0 Then J=26 'at a time Count=Count+1 'until count Wend 'is 26. I=I+2 'I=next odd If I=27 Then A$="" 'Restart A$ after NextDec$=Dec$ 'final decimation End Function 'NextDec$ 'Returns score for Al$, block width N Function KMScore(Al$,N) Tmp$=Al$+Al$ : Score=0 For I=1 to 26 'I is posn in alphabet Count=1 'Number of ltrs in unit For J=I to I+25 'J=posn in Ith unit CurLtr = ASC(Mid$(Tmp$,J,1)) NxtLtr = ASC(Mid$(Tmp$,J+1,1)) If CurLtr+N >NxtLtr Then Exit For Count=Count+1 'Count ltr if block Next J 'width permits If Count > 1 then Score=Score + Count*Count End If Next I KMScore=Score End Function 'KMScore 'Right-justify I in field of length L Function RJust$(I,L) Tmp$=Space$(L)+Ltrim$(Str$(I)) RJust$=Right$(Tmp$,L) End Function 'RJust$