Solved

# ROT13 function & procedure

Posted on 2010-08-24
Medium Priority
1,407 Views

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
0
• 3
• 2
• 2
• +1

LVL 8

Expert Comment

ID: 33516184
are you looking for this code   http://www.linuxhilfen.org/c/c_aufsteiger_rot.html    converted to pascal ?
0

LVL 8

Expert Comment

ID: 33516212
0

LVL 4

Expert Comment

ID: 33516391
Found something, hope it is what you need :)
``````function ROT13(AStr: String): String;
var
i: integer;
c: char;
begin
for i := 1 to Length(AStr) do begin
c := AStr[i];

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);

Result := Result + c;
end;
end;
``````
0

Author Comment

ID: 33516897
@bjove:

that works if you use the same function to encrypt and decrypt. I was looking for a function that you passed another parameter (Tciphermode)

also, a procedure that does the same, but uses a TSringList

0

LVL 4

Accepted Solution

bjove earned 2000 total points
ID: 33517018
Why do you need cMode param? Same function encrypts and decrypts.
``````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;
``````
0

LVL 32

Expert Comment

ID: 33517336

ROT13 works like the classic XOR ecyption/decryption. The same code works both ways so you dont need to specify in your code that you are either cyphering or decyphering
0

Author Comment

ID: 33517860
@ewangoya

but thats what i am looking for

i can google all the code that has been offered already here.

I am looking for way - if its possible, to encrypt, and decrypt
0

LVL 8

Expert Comment

ID: 33518528
if you execute  rot13 function twice you get the original message back

use the rot13 code from   http://forum.delphi-treff.de/showthread.php?24859-Algorithmen-Rot13

and make a button like

procedure TForm1.Rot13_ButtonClick(Sender: TObject);
begin
MsgEdit.text := ROT13_DeCode(MsgEdit.text);
end;

it does nor make any sense a separate encrypt, and decrypt   function

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi. Ā  One of the more specific questions is how to show progress of the thread. Ā  Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to theā¦
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGridā¦
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
###### Suggested Courses
Course of the Month16 days, 17 hours left to enroll