#define key 123
#define C1 52845
#define C2 22719CString CCrypt::Decrypt(CString S, WORD Key)
{
CString Result,str;
int i,j;
Result.Empty();
for(i=0;i<S.GetLength()/2;i++)
{
j=((BYTE)S.GetAt(2*i)-65)*26;
j+=(BYTE)S.GetAt(2*i+1)-65;
str="1";
str.SetAt(0,j);
Result+=str;
}
S=Result;
for(i=0;i<S.GetLength();i++)
{
Result.SetAt(i,(BYTE)S.GetAt(i)^(Key>>8));
Key=((BYTE)S.GetAt(i)+Key)*C1+C2;
}
return Result;
哪位高手能把这段函数转化成delphi啊?
#define C1 52845
#define C2 22719CString CCrypt::Decrypt(CString S, WORD Key)
{
CString Result,str;
int i,j;
Result.Empty();
for(i=0;i<S.GetLength()/2;i++)
{
j=((BYTE)S.GetAt(2*i)-65)*26;
j+=(BYTE)S.GetAt(2*i+1)-65;
str="1";
str.SetAt(0,j);
Result+=str;
}
S=Result;
for(i=0;i<S.GetLength();i++)
{
Result.SetAt(i,(BYTE)S.GetAt(i)^(Key>>8));
Key=((BYTE)S.GetAt(i)+Key)*C1+C2;
}
return Result;
哪位高手能把这段函数转化成delphi啊?
C1 = 52845;
C2 = 22719;function TForm1.Decrypt(srcPchar: pchar; key: WORD): String;
var
i,j: Integer;
strTmp: String;
aryTmp: array of Byte;
begin
strTmp := '';
for i := 0 to (length(srcPchar) div 2 - 1) do
begin
j := (Byte(srcPchar[2*i]) - 65) * 26;
j := j + Byte(srcPchar[2*i + 1]) - 65;
strTmp := strTmp + string(char(j));
end;
srcPchar := pchar(strTmp);
SetLength(aryTmp,length(srcPchar));
for i := 0 to (length(srcPchar) - 1) do
begin
aryTmp[i] := byte(srcPchar[i]);
end; for i := 0 to (length(srcPchar) - 1) do
begin
strTmp[i + 1] := char(aryTmp[i] xor (key shr 8));
Key := (aryTmp[i] + Key) * C1 + C2;
end;
Result := strTmp;
end;// 用法
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(Decrypt(pchar('dsklkjfdsklj'),125));
end;