Anonymous user
Playfair cipher: Difference between revisions
m
→{{header|REXX}}: performed some subroutine statement reductions. -- ~~~~
m (→{{header|REXX}}: converted a subroutine to in-line. -- ~~~~) |
m (→{{header|REXX}}: performed some subroutine statement reductions. -- ~~~~) |
||
Line 360:
=={{header|REXX}}==
Quite a bit of the REXX code deals with error checking, accepting arguments, and displaying the options used.
<lang rexx>/*REXX program implements a PLAYFAIR cypher (encryption & decryption).*/
arg oldK noX _ . '(' oldX
Line 400 ⟶ 401:
@@: parse arg Xrow,Xcol; return @.Xrow.Xcol
err: say; say '***error!***' arg(1); say; exit 13
row: ?=pos(arg(1),grid); _=(?-1)//5+1; return (4+?)%5
/*──────────────────────────────────SCRUB subroutine────────────────────*/
scrub: procedure; arg stuff /* ARG capitalizes all arguments.*/
Line 417 ⟶ 416:
/*──────────────────────────────────.PLAYFAIR subroutine────────────────*/
.playfair: parse arg T,encrypt; i=-1; if encrypt then i=1; $=
do k=1 while encrypt;
if _==substr(T,k+1,1) then T=left(T,k) || 'X' || substr(T,k+1)
end /*k*/
do j=1 by 2 to length(T); __=strip(substr(T,j,2)); call LR
if len==1
select
when rowL==rowR then __=@@(rowL, colL+i)@@(rowR, colR+i) /*rule 2*/
Line 428 ⟶ 426:
otherwise __=@@(rowL, colR )@@(rowR, colL) /*rule 4*/
end /*select*/
$=$ || __
end /*j*/
|