Rot13 in Pascal

Published on 21 July 2025 (Updated: 21 July 2025)

Welcome to the Rot13 in Pascal page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

program Rot13;

{$mode objfpc}{$H+}

uses
   SysUtils;

procedure ShowUsage;
begin
   Writeln('Usage: please provide a string to encrypt');
   Halt(1);
end;

function Rot13(const S: string): string;
var
   ch: char;
begin
   Result := '';
   for ch in S do
      case ch of
         'A'..'Z':
            Result += Chr(((Ord(ch) - Ord('A') + 13) mod 26) + Ord('A'));
         'a'..'z':
            Result += Chr(((Ord(ch) - Ord('a') + 13) mod 26) + Ord('a'));
         else
            Result += ch;
      end;
end;

var
   Input: string;
begin
   if ParamCount <> 1 then
      ShowUsage;

   Input := ParamStr(1);
   if Input = '' then
      ShowUsage;

   Writeln(Rot13(Input));
end.

Rot13 in Pascal was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.