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

  • Home
  • SEARCH
  • 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 3800128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:50:41+00:00 2026-05-19T13:50:41+00:00

I am trying to create a PHP script, and a Delphi program to talk

  • 0

I am trying to create a PHP script, and a Delphi program to “talk” with it. In order to keep it secure, I want to encrypt the outgoing text from both sides, so it makes to use the same encryption function on both ends.

This is the function I found for PHP:

function convert($str,$ky=''){
  if($ky=='')return $str;
  $ky=str_replace(chr(32),'',$ky);
  if(strlen($ky)<8)exit('key error');
  $kl=strlen($ky)<32?strlen($ky):32;
  $k=array();
  for($i=0;$i<$kl;$i++){
    $k[$i]=ord($ky{$i})&0x1F;
  }
  $j=0;
  for($i=0;$i<strlen($str);$i++){
    $e=ord($str{$i});
    $str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e);
    $j++;
    $j=$j==$kl?0:$j;
  }
  return $str;
} 

I cant seem to be able to convert it to Delphi. Help is greatly apreciated!
Thanks, Jeff

  • 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-19T13:50:42+00:00Added an answer on May 19, 2026 at 1:50 pm

    It’s a function that receives two strings and returns another string. I’ll include variable declarations in comments as they’re introduced in the code; put them at the top of the function.

    function convert(str: AnsiString; const key: AnsiString = ''): AnsiString;
    

    If the key is empty, then the result is simply str:

    begin
      if key = '' then
        Exit(str);
    

    The first parameter is the value to be “encrypted,” and the second is the key to use for that encryption. The key needs to be at least eight non-space characters long; anything beyond 32 is ignored. If the key is too short, the PHP script would terminate; we’ll use Delphi’s Assert statement instead since it’s clear that the code should never even have executed if the key is wrong. (Script-termination is not a recoverable error that the user would be expected to fix.) The PHP code uses the ?: operator to select the desired value for the length, but Delphi’s Min function (from the Math unit) expresses the desire more clearly.

      // var ky: AnsiString;
      ky := StringReplace(key, ' ', '', [rfReplaceAll]);
      Assert(Length(ky) >= 8, 'key error');
      // var kl: Integer;
      kl := Min(Length(ky), 32);
    

    The array k is used to hold numbers representing the lower five bits of each character in the key. In PHP, an array will automatically grow to whatever size it needs based on the index used. In Delphi, we need to allocate the space in advance. Since it’s set in a loop that goes over each character of the key, we know the array will be the same length.

      // var k: array of Byte;
      SetLength(k, kl);
      // var i: Integer;
      for i := 0 to Pred(kl) do
        k[i] := Ord(ky[i+1]) and $1f;
    

    Next, each character in the string that has its seventh bit set gets modified according to each successive byte in the k array. The j variable keeps track of which key byte we’ll use next.

      // var j: Integer;
      j := 0;
      for i := 1 to Length(str) do begin
        // var e: Byte;
        e := Ord(str[i]);
        if (e and $e0) <> 0 then
          str[i] := AnsiChar(e xor k[j]);
        Inc(j);
        if j = kl then
          j := 0;
        // The previous three lines can also be written j := (j + 1) mod kl
      end;
    

    Finally, we return the new value of str:

      Result := str;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a PHP script to get the app version from
Using php, I'm trying to create a script which will search within a text
I'm trying to create system users with a php script securely, In that, I'd
i'm trying to create nodes and taxonomy terms through a custom php script by
I'm trying to create a php script that will handle a mailing list for
I am currently trying to create a PHP script whereby there is already a
I am trying to create a little php script that can make my life
I am trying to create a user login/creation script in PHP and would like
I am trying to create a php script that inputs the HTTP links pasted
I'm trying to create a PHP script that will return some details of each

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.