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 610231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:39:09+00:00 2026-05-13T17:39:09+00:00

I need to convert this code into Delphi. But it’s too complicated to handle…

  • 0

I need to convert this code into Delphi. But it’s too complicated to handle…

Thanks…

String key = xorString("STACKOVERFLOWCOM", "ASDFQWERTYKMLYDR");

String xorString(String txt, String xor) {
  StringBuffer str = new StringBuffer();
  for( int i = 0; i < txt.length(); i++ ) {
    int ch = txt.charAt(i) ^ xor.charAt(i);
    char digit = getHexDigit((ch >> 4) & 0x0f);
    str.append(digit);
    digit = getHexDigit(ch & 0x0f);
    str.append(digit);
  } // for()
  return str.toString();
} // xorString()

char getHexDigit(int nibble) {
  if( nibble >= 0 && nibble <= 9 ) return (char)((int)'0' + nibble);

  return (char)((int)'A' + nibble - 10);
} // getHexDigit()
  • 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-13T17:39:09+00:00Added an answer on May 13, 2026 at 5:39 pm

    What this is doing is pretty straightforward, really. It’s taking an input string and a key and XORing them together, then returning the result as a stream of hex digits. Here’s the Delphi equivalent:

    function xorString(txt, key: string): string;
    var
      i: integer;
      ch: byte; //change to word for D2009+
      digit: string;
    begin
      result := '';
      for i := 1 to length(txt) do
      begin
        ch := byte(txt[i]) xor byte(key[i]); //change byte to word for D2009+
        digit := IntToHex(ch, 2);
        result := result + digit;
      end;
    end;
    

    I didn’t bother translating the GetHexDigit routine, since SysUtils.IntToHex performs the same function. Also, as Ulrichb pointed out, this requires a key string at least as long as the “txt” string. Otherwise, you’ll get a range check error. (You are compiling with range checking on, right?)

    EDIT: Not sure why the >> 4 and 0x0f bit is there when converting. I don’t have a Java compiler handy, so it might just be a language issue, but it looks to me like this bitshifting will always produce results within 0..3 for alphabetical characters, and also make it impossible to reverse the process, which is usually the entire point of xor encryption. If you don’t need to maintain compatibility with this Java algorithm, I’d replace the digit line with:

    digit := intToHex(ch, 2);
    

    which will give you a more correct and reversible result.

    EDIT2: OK, it was a little too early in the morning to be doing heavy logic when I wrote that. I totally missed the fact that it was calling GetHexDigit twice. Fixed the algorithm.

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

Sidebar

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.