'Copyright 2001 The American Cryptogram Association (ACA) '3613 Piedmont Drive, Plano TX 75075-6234 'All rights reserved. 'Contains digraph evaluation routines 'which will be used in other Computer 'Column programs. See May/June 2001 'Computer Column for further explanation 'of these routines 'PtaxStat.Bas (Ct$ from Novice Notes) Ct$="UXCUDZMVBAFWWPVDIKDOJISMAWRBBAY" Ct$=Ct$+"LOYXAKUXRJGDCJMYAPVRJWJADMU" Ct$=Ct$+"KLKLUAMKAOENYBFCCIQGFKQZAA" If Len(Ct$) mod 2 <> 0 then Print "Cipher length must be even." System 'Exit QBasic environment End If 'Find period with best digraph ltrs For Per=3 to 16 Depth = (len(ct$)/2)\Per Pairs$="" 'Each row is For Row=0 to Depth-1'2 letters deep. RowS= Row*per*2 'Start of row txt For Col=1 to Per 'Decode col pairs Top$=Mid$(Ct$,RowS+Col,1) Bot$=Mid$(Ct$,RowS+Col+Per,1) Pairs$=Pairs$+PortaxDg$(Top$+Bot$) Next Col Next Row Avg=DiAvg(Pairs$,1) 'Score the text If Avg > HiA Then HiA=Avg :HiP=Per Next Per Print "High-scoring period =";HiP; Print "with digraph average =";HiA Print "Probably cipher is "; If HiA < 580 Then Print "not "; Print "Portax." : System 'Returns decryption of Portax 'digraph Dg$ if Dg$ begins N-Z. Function PortaxDg$(Dg$) Dec$="" 'Return null if decrypt fails T$=Mid$(Dg$,1,1) : B$=Mid$(Dg$,2,1) T=ASC(T$)-77 : T=T+T-1 : B=ASC(B$)-64 If T > 0 Then 'Dg$ begins N-Z If (B mod 2) = 0 Then T=T+1 If T<>B Then Dec$= Chr$(77+(B+1)\2)+Chr$(64+T) End If End If PortaxDg$ = Dec$ End Function 'PtxDg$() 'Corrected Nov/Dec 2001 Function DiAvg(S$,A) DLen%= Len(S$) - 1 If A<>1 then Dlen%=((Dlen%-1)\2)+1 DiAvg = Int(100*(DiSum(S$,A)/Dlen%)) End Function 'DiAvg Function DiSum(S$,A) Static IF Init%=0 Then DIM Di%(26,26) d$=d$+"47874675736879373989676574742" d$=d$+"08111630721710653712060825273" d$=d$+"28727621822647613040765686558" d$=d$+"43665753677656062978887667458" d$=d$+"79775998577673745376447226538" d$=d$+"40757624050755475577326557527" d$=d$+"66635051854494348315548426576" d$=d$+"25050758777744258797647884735" d$=d$+"05500040003000005000006000005" d$=d$+"43274246224365313653040508557" d$=d$+"85448258548524666550718643842" d$=d$+"47104647613656140608678869684" d$=d$+"66568535896563626677686663678" d$=d$+"97729789684537333732672173276" d$=d$+"07666030400000000000000000000" d$=d$+"06000008667966583666686368865" d$=d$+"60718676865784666687458974706" d$=d$+"28665865983366596278874707266" d$=d$+"76646462377856088833434361008" d$=d$+"00070000050001021003073347328" d$=d$+"72244673055521403141424203510" d$=d$+"11035012520223066666655633565" d$=d$+"86357643624240005000300200300" d$=d$+"010200044" For I%=0 to 675 'Build Di% Table C$=Mid$(D$,I%+1,1): V% = Val(C$) Di%((I%\26)+1,(I% mod 26)+1)=V% Next I% d$="" : Init%=1 'Initialization done End If TLen%=Len(S$)-1 : Sum%=0 :Stp%=2 If A=1 Then Stp%=1 For I%=1 to TLen% Step Stp% R%=Asc(Mid$(S$,I%,1))-64 C%=Asc(Mid$(S$,I%+1,1))-64 Sum%=Sum%+Di%(R%,C%) Next I% DiSum = Sum% End Function 'DiSum