求助:帮我看看Delphi一个解密代码哪里错了?
大佬帮我看看以下代码是一个解密的代码,哪里出问题了,解密出来的十六进制好像是对的,可是转换成字符串不对,是什么问题帮忙指出并告诉我怎么修改,谢谢了
function Decode(source : string):string; //解密
function strToHexStr(str:string):string; //字符串转换成16字符串
function HexStrToStr(const S:string):string; //16进制字符串转换成字符串
//解密
function Decode(source : string):string;
var
Source_Len,Len : integer;
Count,c1,c2 : integer;
code : array[0..7] of byte;
a1,a2 : byte;
ind : dword;
Decode_Str : string;
label L1,L2;
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 (Count < Source_Len) do
begin
if(ord(Source[Count+1]) - $3c) < 0 then
begin
Decode_Str := Decode_Str + Source[Count+1];
inc(Len);
inc(Count);
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Continue;
//break;
end;
a1 := ord(Source[Count+1]) - $3c;
if Len >= Source_Len then
begin
break;
end;
if (c2 + 6) < 8 then
begin
goto L2;
end;
ind := a1 and $3f;
ind := ind shr (6-c1);
Decode_Str := Decode_Str + chr(ind or a2);
Inc(Len);
c2 := 0;
if c1 >= 6 then
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;
//字符串转换成16字符串
function strToHexStr(str:string):string;
var
c:char;
ss:string;
i:integer;
begin
while str<>'' do begin
c:=str[1];
ss:=ss+format('%0x',[ord(c)]);
delete(str,1,1);
end;
strtohexStr:= ss;
end;
//16进制字符串转换成字符串
function HexStrToStr(const S:string):string;
var
t:Integer;
ts:string;
M,Code:Integer;
begin
t:=1;
Result:='';
while t<=Length(S) do
begin //xlh 2006.10.21
while (t<=Length(S)) and (not (S[t] in ['0'..'9','A'..'F','a'..'f'])) do
inc(t);
if (t+1>Length(S))or(not (S[t+1] in ['0'..'9','A'..'F','a'..'f'])) then
ts:='$'+S[t]
else
ts:='$'+S[t]+S[t+1];
Val(ts,M,Code);
if Code=0 then
Result:=Result+Chr(M);
inc(t,2);
end;
end;
调用
procedure TForm1.Button2Click(Sender: TObject);
begin
// edit2=23 32 6C 48 56 6F 41 4C 3C 3C 3C 3C 3E 78 3C 3C 3C 3C 52 68 70 3E 3C 3C 64 5A 7A 5D 77 78 4E 63 65 48 76 79 75 46 43 6B 64 5A 78 21
edit1.Text:=strToHexStr(Decode(HexStrToStr(edit2.Text)));
edit3.Text:=HexStrToStr(edit1.Text);
end;
请问哪里不对呢