60 lines
1.3 KiB
Text
60 lines
1.3 KiB
Text
rot13_test:
|
|
procedure options(main);
|
|
|
|
%replace
|
|
true by '1'b,
|
|
false by '0'b;
|
|
|
|
dcl (plain, encoded) char(127) varying;
|
|
|
|
plain = 'The quick brown fox jumps over the lazy red dog.';
|
|
put skip list ('Plain text:', plain);
|
|
encoded = rot13(plain);
|
|
put skip list ('Encoded :', encoded);
|
|
put skip list ('Restored :', rot13(encoded));
|
|
|
|
stop;
|
|
|
|
rot13:
|
|
procedure (s) returns (char(127) varying);
|
|
dcl
|
|
s char(127) varying,
|
|
ch char(1),
|
|
i fixed bin(15);
|
|
do i = 1 to length(s);
|
|
ch = substr(s,i,1);
|
|
if (isalpha(ch)) then
|
|
do;
|
|
if (toupper(ch) > 'M') then
|
|
ch = ascii(rank(ch) - 13);
|
|
else
|
|
ch = ascii(rank(ch) + 13);
|
|
end;
|
|
substr(s,i,1) = ch;
|
|
end;
|
|
return (s);
|
|
end rot13;
|
|
|
|
toupper:
|
|
procedure (ch) returns (char(1));
|
|
dcl ch char(1);
|
|
dcl cout char(1);
|
|
if ((ch >= 'a') & (ch <= 'z')) then
|
|
cout = ascii(rank(ch) - 32);
|
|
else
|
|
cout = ch;
|
|
return (cout);
|
|
end toupper;
|
|
|
|
isalpha:
|
|
procedure (ch) returns (bit(1));
|
|
dcl ch char(1);
|
|
if (((ch >= 'A') & (ch <= 'Z')) |
|
|
((ch >= 'a') & (ch <= 'z'))) then
|
|
return (true);
|
|
else
|
|
return (false);
|
|
end isalpha;
|
|
|
|
|
|
end rot13_test;
|