Another Silly programming puzzle....

340 Ok dgr0093%ritcv at cs.rit.edu
Fri Apr 7 10:35:27 AEST 1989


I wasn't going to post this, but decoding rot13 text is much easier than that
last program would indicate. I wrote this a few months ago, and it's a full
text filter, so you can pipe things at it as well as calling it with a 
filename to translate. I find the "text filter guts" very useful for building
other simple text filters.

Of course, "rot13 file | rot13" just types out the original file, so you can be
silly with it, too, if you're so inclined. :)

program rot13;

type
  line = string[120];

var
  buf: line;

  function rot13 (inp:line): line;

  var
    count: integer;

  begin
    for count := 1 to length(inp) do
      case inp[count] of
        'A'..'M', 'a'..'m': inp[count] := chr(ord(inp[count])+13);
        'N'..'Z', 'n'..'z': inp[count] := chr(ord(inp[count])-13)
      end;
    rot13 := inp
  end;

begin
  if paramcount > 0 then begin
    close (input);
    assign (input, paramstr(1));
    {$I-} reset (input); {$I+}
    if ioresult <> 0 then begin
      writeln ('Error opening ',paramstr(1), ' as input: aborting');
      halt
    end
  end;
  repeat
    readln (buf);
    writeln (rot13(buf))
  until eof (input)
end.

-------------------------------------------------------------------
  Dave Rutherford   Michelangelo H. Jones   DGR0093 at RITVAX.BITNET
-------------------------------------------------------------------



More information about the Comp.lang.c mailing list