Playfair cipher: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed an error message concerning when the specified Playfair cypher key is too short. -- ~~~~) |
(→{{header|REXX}}: fixed two unset variables. -- ~~~~) |
||
Line 372: | Line 372: | ||
if newX=='' then call err 'PHRASE is empty or has no letters' |
if newX=='' then call err 'PHRASE is empty or has no letters' |
||
if length(noX)\==1 then call err '"omitted" letter must be only one letter' |
if length(noX)\==1 then call err '"omitted" letter must be only one letter' |
||
⚫ | |||
if \datatype(noX,'M') then call err '"omitted" letter must be a Latin alphabet letter.' |
if \datatype(noX,'M') then call err '"omitted" letter must be a Latin alphabet letter.' |
||
if pos(noX,oldX)\==0 then call err 'PHRASE can''t contain the "OMIT" character: ' noX |
if pos(noX,oldX)\==0 then call err 'PHRASE can''t contain the "OMIT" character: ' noX |
||
Line 380: | Line 379: | ||
if pos(_,newK)==0 then newK=newK || _ |
if pos(_,newK)==0 then newK=newK || _ |
||
end /*j*/ |
end /*j*/ |
||
⚫ | |||
fill=space(translate(fill,,newK),0) /*remove any cypher characters. */ |
fill=space(translate(fill,,newK),0) /*remove any cypher characters. */ |
||
grid=left(newK || fill,26) /*use only the first 25 chars. */ |
grid=left(newK || fill,26) /*use only the first 25 chars. */ |
||
Line 420: | Line 420: | ||
end /*k*/ |
end /*k*/ |
||
do j=1 by 2 to length(T); __=strip(substr(T,j,2)); call LR |
do j=1 by 2 to length(T); __=strip(substr(T,j,2)); call LR |
||
if |
if length(__)==1 then __=__ || 'X'; call LR /*append an "X" character, rule 1*/ |
||
select |
select |
||
when rowL==rowR then __=@@(rowL, colL+i)@@(rowR, colR+i) /*rule 2*/ |
when rowL==rowR then __=@@(rowL, colL+i)@@(rowR, colR+i) /*rule 2*/ |