有没有高手将这部分Delphi代码翻译成C语言的?

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:27:24
function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * 11 + 12;
end
else
begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * 11 + 12;
end;
end;
end;

因为都是对数据的位操作,所以请务必精确,注意不通语言数据类型的差异。多谢
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * 11 + 12;
end
else
begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * 11 + 12;
end;
主要是这一段,没有定义的函数不用管

char res[128];

//HexToStr是DELPHI实用库,标准C没有直接能用的函数可用?

for(i=0;i<strlen(s1))
{
if(s1[i]^(key>>8)=='\0')
{res[i]=s1[i];key=key*11+12;}
else
{res[i]=s1[i]^(key>>8);
key=(s1[i]+key)*11+12;}
}
return res;
}