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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:08:33+00:00 2026-06-02T10:08:33+00:00

I have a problem with a Delphi 7 string-decoder function (Decrypt) I found online.

  • 0

I have a problem with a Delphi 7 string-decoder function (“Decrypt”) I found online. It takes a string and four numeric values between 1 and 120 to decode it. Putting the function within an executable and running it works great. However, I want to run this within a DLL. I’m using an extra function to receive the necessary values from the calling task and call the decrypt function from there. For some reason I can’t put my finger on, the host app crashes every time the dll calls the decrypt-function. For the last few hours I have been trying everything I could come up with to get this to work, but without success. I’m new to Delphi and Pascal in general, so may be I just overlooked something obvious. Either way, I’m lost. Any help would be greatly appreciated.

Edit: Here’s the windows error that pops up upon crash:

  Fault Module Name:    StackHash_0a9e
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   00000000
  Exception Code:   c0000005
  Exception Offset: 00000000
  OS Version:   6.1.7600.2.0.0.256.1
  Locale ID:    1031
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Here’s the code that I use:

library decrypt_test_dll;

uses
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

function callfunction(externalstring, value1, value2, value3, value4: PAnsiChar):integer; cdecl;
var
  convkey1, convkey2, convkey3, convkey4 : string;
  convstring, decodedstring : string;
  Decrypt : function(Text : string; Key1, Key2, Key3, Key4 : Integer) : string;
begin
  convkey1 := value1;
  convkey2 := value2;
  convkey3 := value3;
  convkey4 := value4;
  convstring := externalstring;
  decodedstring := Decrypt(externalstring, strtoint(convkey1), strtoint(convkey2), strtoint(convkey3), strtoint(convkey4));
  showmessage(decodedstring);
end;

function Decrypt(Text : string; Key1, Key2, Key3, Key4 : Integer) : string;
var
 BufS, Hexa1, Hexa2 : string;
  BufI, BufI2, Divzr, Sc, Sl, Num1, Num2, Num3, Num4, Res1, Res2, Res3, Res4 : Integer;
begin
  showmessage('within decryption function');
 Sl := Length(Text);
  Sc := 0;
  BufS := '';
  if (Key1 in [1 .. 120]) and (Key2 in [1 .. 120]) and (Key3 in [1 .. 120]) and (Key4 in [1 .. 120]) then
    begin
      Divzr := Key1 * Key4;
      BufI2 := Key3 * Key2;
      Divzr := Divzr - BufI2;
      if Divzr = 0 then
        begin
          Result := '';
          Exit;
        end;
    end
  else
    begin
      Result := '';
      Exit;
    end;
  repeat
    for BufI := 1 to 4 do
      begin
        Inc(Sc);
        Hexa1 := IntToHex(Ord(Text[Sc]), 2);
        Inc(Sc);
        Hexa2 := IntToHex(Ord(Text[Sc]), 2);
        if Hexa1 = 'FF' then
          begin
            Hexa1 := '00';
            Hexa2 := '00';
          end;
        if Hexa1 = 'FE' then Hexa1 := '00';
        if Hexa1 = 'FD' then
          begin
            Hexa1 := Hexa2;
            Hexa2 := '00';
          end;
        case BufI of
          1 : Res1 := StrToInt('$' + Hexa1 + Hexa2);
          2 : Res2 := StrToInt('$' + Hexa1 + Hexa2);
          3 : Res3 := StrToInt('$' + Hexa1 + Hexa2);
          4 : Res4 := StrToInt('$' + Hexa1 + Hexa2);
        end;
      end;
    BufI := Res1 * Key4;
    BufI2 := Res2 * Key3;
    Num1 := BufI - BufI2;
    Num1 := Num1 div Divzr;
    BufI := Res2 * Key1;
    BufI2 := Res1 * Key2;
    Num2 := BufI - BufI2;
    Num2 := Num2 div Divzr;
    BufI := Res3 * Key4;
    BufI2 := Res4 * Key3;
    Num3 := BufI - BufI2;
    Num3 := Num3 div Divzr;
    BufI := Res4 * Key1;
    BufI2 := Res3 * Key2;
    Num4 := BufI - BufI2;
    Num4 := Num4 div Divzr;
    BufS := BufS + Chr(Num1) + Chr(Num2) + Chr(Num3) + Chr(Num4);
    until Sc >= Sl;
    Result := BufS;
end;

exports
  Decrypt index 1,
  callfunction index 2;

begin
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-06-02T10:08:34+00:00Added an answer on June 2, 2026 at 10:08 am

    This code is all wrong:

    function callfunction(externalstring, value1, value2, value3, value4: PAnsiChar):integer; cdecl;
    var
      convkey1, convkey2, convkey3, convkey4 : string;
      convstring, decodedstring : string;
      Decrypt : function(Text : string; Key1, Key2, Key3, Key4 : Integer) : string;
    begin
      convkey1 := value1;
      convkey2 := value2;
      convkey3 := value3;
      convkey4 := value4;
      convstring := externalstring;
      decodedstring := Decrypt(externalstring, strtoint(convkey1), strtoint(convkey2), strtoint(convkey3), strtoint(convkey4));
      showmessage(decodedstring);
    end;
    

    The local variable Decrypt is never assigned to. So when you call Decrypt, anything can happen. You need to move callfunction to the bottom of the unit so that it appears after the real Decrypt. And you need to remove the function pointer variable.

    function callfunction(externalstring, value1, value2, value3, value4: PAnsiChar):integer; cdecl;
    var
      convkey1, convkey2, convkey3, convkey4 : string;
      convstring, decodedstring : string;
    begin
      convkey1 := value1;
      convkey2 := value2;
      convkey3 := value3;
      convkey4 := value4;
      convstring := externalstring;
      decodedstring := Decrypt(externalstring, strtoint(convkey1), strtoint(convkey2), strtoint(convkey3), strtoint(convkey4));
      showmessage(decodedstring);
    end;
    

    You also should not use string as a parameter (or indeed a return value) in an exported DLL function. It’s not a valid type for interop since it relies on both sides of the interface using the same string implementation, and the same memory manager. You need to find a different way to define the Decrypt interface, if you are going to export it. Or possibly you should not be exporting that function at all. Impossible for me to know with any certainty. My guess is that you are actually calling callfunction rather than Decrypt from the calling code. Anyway, in its current state, you must not export Decrypt.

    One other point to make. When you ask a question that involves a module interface, you should always show both sides of the interface. Here you have shown the DLL, but not the code that calls into the DLL. The error could be there. Indeed, there could be an error there in addition to the errors I have pointed out.

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

Sidebar

Related Questions

I have problem with Indy IdHttp Post method. Function CallRpc() compiled with Delphi 2007
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have a problem with setting Browsing Path in Delphi 2009: When I install
I have started using of generics in Delphi 2010 but I have a problem
Possible Duplicate: What's wrong with Delphi's “with” I am have a problem debugging code
I have a very strange problem with the Delphi 2006 IDE. If the IDE
I have quite a problem concerning the use of relational database concepts in Delphi
I have this weird problem that a convert of a string on my machine
I have Delphi lib which must return information read via socket. function GetBufferInfo(Address: PChar):
I have the following function that works in Delphi 2006, but under Delphi XE2

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.