Question : ROT13 function & procedure


I need a delphi 2010 function abd procedure for solving ROT13 using string and stringlist


something like


Tciphermode = (cmEncrypt, cmDecrypt)

function ROT13(AStr: String; cMode: TcipherMode): String;
begin
 //
 result:=
end;


procedure ROT13(Lines: TStringList; cMode: TcipherMode)
begin
 //
end;

thanks

Answer : ROT13 function & procedure

Why do you need cMode param? Same function encrypts and decrypts.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure ROT13(AStrLst: TStringList);
var
  i, j: integer;
  c: char;
  AStr: string;
  s: string;
begin

  for i := 0 to AStrLst.Count - 1 do begin
    AStr := AStrLst[i];
    s := '';
    for j := 1 to Length(AStr) do begin
      c := AStr[j];

      if (((c >= 'A') AND (c <= 'M')) OR ((c >= 'a') AND (c <= 'm'))) then
        c := chr(ord(c) + 13)
      else if (((c >= 'N') AND (c <= 'Z')) OR ((c >= 'n') AND (c <= 'z'))) then
        c := chr(ord(c) - 13);

      s := s + c;
    end;
    AStrLst[i] := s;
  end;
end;
Random Solutions  
 
programming4us programming4us