Home > Back-end >  For help: help me to look at Delphi where a decryption code is wrong?
For help: help me to look at Delphi where a decryption code is wrong?

Time:11-02

Who help me to look at the following code is a decryption code, what is going wrong, decrypt a hex is right, but converted to string is wrong, what's the problem to help point out and tell me how to modify, thank you
The function of Decode (source: string) : string;//decryption
The function strToHexStr (STR: string) : string;//string into 16 string
The function HexStrToStr (const S: string) : string;//hexadecimal string into a string

//decryption
The function of Decode (source: string) : string;
Var
Source_Len, Len: integer;
The Count, c1 and c2: integer;
Code: an array of byte [0.. 7];
A1, a2: byte;
Ind: dword;
Decode_Str: string;
Label L1 and L2;
The begin
Result:=';
Decode_Str:=';
Code [2] :=$fc;
Code [4] :=$f0;
Code [6] :=$c0;
Len:=0;
A1:=0;
A2:=0;
C1:=2;
C2:=0;
Ind:=0;
Count:=0;
Source_Len:=Length (source);
While (the Count & lt; Source_Len) do
The begin
If (word (Source) [Count + 1] - $3 c) & lt; 0 then
The begin
Decode_Str:=Decode_Str + Source [Count + 1];
Inc (Len);
Inc (Count);
A1:=0;
A2:=0;
C1:=2;
C2:=0;
Ind:=0;
The Continue;
//break;
end;
A1:=word (Source) [Count + 1] - $3 c;
If Len & gt;=Source_Len then
The begin
break;
end;
If (c2 + 6) & lt; 8 then
The begin
Goto L2;
end;
Ind:=a1 and $3 f;
Ind:=ind SHR (6 - c1);
Decode_Str:=Decode_Str + CRH (ind or a2);
Inc (Len);
C2:=0;
If c1 & gt; 6 then=
The begin
C1:=2;
Goto L1.
end;
Inc (c1, 2);
L2: a2:=a1 SHL c1;
A2:=a2 and code [c1];
C2:=c2 + (8 - c1);
L1: inc (count);
end;
SetLength (Decode_Str, Len);
Result:=Decode_Str;
end;

//string into 16 string

The function strToHexStr (STR: string) : string;
Var
C: char;
Ss: string;
I: integer;
The begin
While str<> ' 'do begin
C:=STR [1].
Ss:=ss + format (' % 0 x '[word] (c));
Delete (STR, 1, 1);
end;
StrtohexStr:=ss;
end;

//hexadecimal string into a string
The function HexStrToStr (const S: string) : string;
Var
T: Integer;
Ts: the string;
M, Code: Integer;
The begin
T:=1;
Result:=';
While t<=Length (S) do
The begin//XLH 2006.10.21
While (t<=Length (S)) and (not (S [t] in [' 0 '... '9', 'A'. The 'F', 'A'. The 'F'])) do
Inc (t);
If (t + 1 & gt; Length (S)) or (not (S (t + 1] in [' 0 '... '9', 'A'. The 'F', 'A'. The 'F'])) then
Ts:='$' + S [t]
The else
Ts:='$' [t] + S + S (t + 1),
Val (ts, M Code);
If Code=0 then
Result: the Result=+ CRH (M);
Inc (t, 2);
end;
end;

The

Procedure TForm1. Button2Click (Sender: TObject);
The begin
//edit2 23 32 6 c 48 to 56 f=41 4 c 3 c and 3 c and 3 c e c 78 3 c and 3 c c 3 c 52, 68, 70 3 e and c 3 c 64 5 a 7 a 5 d 63, 65, 48, 76, 79, 75, 77 78 4 e 46 43 64 5 a, 6 b 78 21
Edit1. Text:=strToHexStr (Decode (HexStrToStr (edit2. Text)));
Edit3. Text:=HexStrToStr (edit1. Text);
end;

What is wrong

CodePudding user response:

The above code no shrinkage, such code, you look good?

CodePudding user response:

refer to the second floor BlueStorm response:
the above code no shrinkage, such code, you look good?


I also copy, make it

CodePudding user response:

See the Decode internal processing should be early AnsiString era code

CodePudding user response:

references 4 floor early play play nuclear response:
see Decode internal processing should be early AnsiString era code

What is wrong

CodePudding user response:

Don't see Encode function, who knows, right?

CodePudding user response:

refer to 6th floor early play big play nuclear response:
Encode function were out of sight, who knows, right?

Some I sent to you

The function Encode (source: string) : string;
Var
Source_Len, Len: integer;
The Count, c: integer;
A1, a2: byte;
Ind: dword;
Encode_Str: string;
The begin
Result:=';
Encode_Str:=';
Len:=0;
A1:=0;
A2:=0;
C:=0;
Ind:=0;
Count:=0;
Source_Len:=Length (source);
While the Count & lt; Source_Len do
The begin
If Len & gt;=$2710 then
break;
Ind:=word (source) [Count + 1];
Ind:=ind SHR (c + 2);
A1:=ind or a2;
A1:=a1 and $3 f;
Ind:=word (source) [Count + 1];
Ind:=ind SHL (8 - (c + 2));
Ind: ind SHR=2;
A2:=ind and $3 f;
Inc (c, 2);
If c & gt; 6 then=
The begin
If Len & gt; Then=$270 f
The begin
Encode_Str:=Encode_Str + CRH (a1 + $3 c);
Inc (Len);
End
The else
The begin
Encode_Str:=Encode_Str + CRH (a1 + $3 c);
Encode_Str:=Encode_Str + CRH (a2 + $3 c);
Inc (Len, 2);
end;
C:=0;
A2:=0;
End
The else
The begin
Encode_Str:=Encode_Str + CRH (a1 + $3 c);
Inc (Len);
end;
Inc (Count);
end;
If c & gt; 0 then
The begin
Encode_Str:=Encode_Str + CRH (a2 + $3 c);
Inc (Len);
end;
SetLength (Encode_Str, Len);
Result:=Encode_Str;
end;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related