Solved

ROT13 function & procedure

Posted on 2010-08-24
8
1,325 Views
Last Modified: 2012-05-10

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
Comment
Question by:Looking_4_Answers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:BdLm
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

by:BdLm
ID: 33516212
0
 
LVL 4

Expert Comment

by:bjove
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;

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Looking_4_Answers
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

your 25% maybe 30% there
0
 
LVL 4

Accepted Solution

by:
bjove earned 500 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;

Open in new window

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 33517336
@Looking_4_Answers

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

by:Looking_4_Answers
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

by:BdLm
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 81
Create a path if not exists 7 108
Unique identifier on a terminal server (rdp) 4 75
Base1 Encode/Decode 3 89
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question