Jump to content

Playfair cipher: Difference between revisions

m
J: discard temps
m (J: discard temps)
Line 237:
 
setkey=:3 :0
key=:. ~.norm y,alph
pairs=:. ,/2{."1 ~."1 (,"0/~alph),"1 norm 'XQV'
mode=:. #.=/"2 inds=:.5 5#:key i.pairs
inds0=:. (0 3,:2 1)&{@,"2 inds
inds1=:.5|1 0+"1 inds NB. same column
inds2=:.5|0 1+"1 inds NB. same row
alt=:,/key{~5 #.mode{"_2_1 inds0,"2 3 inds1,:"2 inds2
ref=:,/pairs
i.0 0
)
Line 253:
 
decrypt=:3 :0
) ,</lang>
,ref{~alt i. 2{."1 -.&' '"1 ~."1 (_2]\ norm y),"1 'XQV'
)</lang>
 
We could obviously factor out a routine to clean the text and form pairs to use for both encrypt and decrypt, but it works well enough like it is.
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.