Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6104565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:51:23+00:00 2026-05-23T13:51:23+00:00

We have a Delphi 2007 routine used to encrypt passwords in a table. The

  • 0

We have a Delphi 2007 routine used to encrypt passwords in a table. The routine was originally grabbed from a CompuServe post a decade or more ago, and a significant amount of data encrypted with this routine exists.

The heart of the original routine is this:

chr(ord(Str[I]) xor not(ord(Id[I mod length(Id) + 1])));

I knew the conversion to Delphi XE would be problematic because of Unicode, so I broke that code out into a function that displays each step of the calculations in a memo:

function TfrmMain.EncodeDecode(AString: string): string;
const
  Hash: string = '^%12h2DBC3f41~~#6093fn7mY7eujEhbFD3DZ|R9aSDVvUY@dk79*7a-|-  Q';
var
  I: Integer;
  IMod: Integer;
  HMod: Char;
  OMod: Integer;
  AStrI: Char;
  OStrI: Integer;
  ResultStr: string;
  XOrNot: Integer;
  ChrXN: AnsiChar;
begin
  Memo1.Clear;
  Memo1.Lines.Add ('AStrI' + TAB + 'IMod' + TAB + 'HMod' +
    TAB + 'OMod' + TAB + 'OStrI' + TAB + 'XOrNot' + TAB + 'ChrXN');

  for I := 1 to Length (AString) do
  begin
    IMod := I mod Length (Hash) + 1;
    HMod := Hash [IMod];
    OMod := Ord (HMod);
    AStrI := AString[I];
    OStrI := Ord (AStrI);  // This is where things go south
    XOrNot := OStrI xor not OMod;
    ChrXN := AnsiChar (XOrNot);
    ResultStr := ResultStr + ChrXN;

    Memo1.Lines.Add (AStrI  + TAB +
      IntToStr (IMod)   + TAB +
      HMod              + TAB +
      IntToStr (OMod)   + TAB +
      IntToStr (OStrI)  + TAB +
      IntToStr (XOrNot) + TAB +
      ChrXN);
  end;
  Memo1.Lines.Add (ResultStr);
  Result := ResultStr;
end;

Like ROT13, the same routine is used to both encrypt and decrypt. If I feed it a string like ‘ABCDEFGHI’, the Delphi 2007 version can take the resulting encrypted string, run it through the same routine, and get back the original string. The version in Delphi XE, however, doesn’t quite work. I’ve made some tweaks (included above) to improve it, but on the OstrI step it falls apart. I think it has something to do with performing an Ord on a (Wide) Char, but that’s the closest I can get.

Any advice greatly appreciated.


Edited

Here is the original Delphi 2007 code:

function EncodeDecode(Str: string): string;
const
  Id: string = '^%12h2DBC3f41~~#6093fn7mY7eujEhbFD3DZ|R9aSDVvUY@dk79*7a-|-  Q';
var
  I: Integer;
begin
  for I := 1 to Length (Str) do
    Str[I] := chr (ord (Str[I]) xor not (ord (Id[I mod Length (Id) + 1])));
  Result := Str;
end;

We actually have to convert this not only to Delphi XE for new versions of our existing software, but also to C# for a new web-based front end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:51:24+00:00Added an answer on May 23, 2026 at 1:51 pm

    Simple approach is, in essence, as follows:

    1. Start with the Delphi 2007 code.
    2. Change string to AnsiString.
    3. Change Char to AnsiChar.
    4. Possibly change Chr() to AnsiChar().

    There may be more nuances to your code. Ideally I’d like to see the original Delphi 2007 version of the code.


    Having posted the original code, I think you should can use this routine in XE:

    function EncodeDecode(const Str: AnsiString): AnsiString;
    const
      Id: AnsiString = '^%12h2DBC3f41~~#6093fn7mY7eujEhbFD3DZ|R9aSDVvUY@dk79*7a-|-  Q';
    var
      I: Integer;
    begin
      Result := Str;
      for I := 1 to Length(Result) do
        Result[I] := AnsiChar(ord(Result[I]) xor not (ord(Id[I mod Length (Id) + 1])));
    end;
    

    Note that I changed the code to take input as a const string and to use Result as the working buffer. This is not necessary for your ANSI/Unicode needs, but feels more natural to me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following Delphi routine is originally from a long-ago CompuServe posting, and is used
I have just ported several of our home-made Outlook COM-addins from Delphi 2007 to
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
I'm upgrading my application from Delphi 2007 to Delphi XE. I have my personal
Delphi 2007. I have a TGrid with more rows than will fit on the
I have updated an application from Delphi 2007 to Delphi 2010, everything went fine,
I have a Java web service to which I've linked from a Delphi 2007
I have problem with Indy IdHttp Post method. Function CallRpc() compiled with Delphi 2007
I have had Delphi 2007 for a while. I tried the Delphi 2009 trial.
I have a Delphi (2007) project which, when I opened it, gave a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.