请教pascal转换翻译为C的代码的问题?
迷死特兔 2006-02-14 12:42:35 下面两个pascal函数,想转换为c代码的,自己写了一下老是有问题,请教一下高手,如何转换翻译:
const
EDC1 = 11; // 常量
EDC2 = 22; // 常量
function Encrypt(S:String;Key:Word):String;
var
I,j:Integer;
begin
Result:=S;
for I:=1 to Length(S) do
begin
Result[I]:=char(byte(S[I]) xor (Key shr 8));
Key:=(byte(Result[I])+Key)*EDC1+EDC2
end;
S:=Result;
Result:='';
for I:=1 to Length(S) do
begin
j:=Integer(s[i]);
Result:=Result+Char(65+(j div 26))+Char(65+(j mod 26));
end;
end;
function Decrypt(S:String;Key:Word):String;
var
I,j:Integer;
begin
Result:='';
for I:=1 to (length(S) div 2) do
begin
j:=(Integer(S[2*i-1])-65)*26;
j:=j+(Integer(S[2*i])-65);
Result:=Result+Char(j);
end;
S:=Result;
for I:=1 to Length(S) do
begin
Result[I]:=Char(byte(S[I]) xor (Key shr 8));
Key:=(byte(S[I])+Key)*EDC1+EDC2;
end;
end;