请教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;
...全文
86 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ma100 2006-02-14
  • 打赏
  • 举报
回复
你转换的贴出来
chenzhichao2008 2006-02-14
  • 打赏
  • 举报
回复
帮你翻译一个

const int EDC1 = 11; // 常量
const int EDC2 = 22; // 常量

string Encrypt(string S,WORD Key)
{
int I,j;
string Result=S;
for( I=1; I < strlen(S); I++ )
{
Result[I]=S[I] ^ (Key >> 8);
Key=(byte(Result[I])+Key)*EDC1+EDC2;
}
S=Result;
Result="";
for( I=1; I < strlen(S); I++ )
{
j=int(s[i]);
Result=Result+char(65+(j / 26))+char(65+(j % 26));
}

return Result;

}

windyloft 2006-02-14
  • 打赏
  • 举报
回复
具体什么地方有问题?

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧