各位谢谢帮我把代码改成delphi好吗?

JeraChen 2004-07-21 04:26:07
int DecodeGate(char *in, char *out)
{
if(in==NULL)
return 0;
int lcnt=strlen(in)>>1;
if(lcnt==0)
return 0;
if(in[0]==(char)0)//'\0' )
return 0;
int i=0;
int icode=0;


int _edi=0xf667;
for(i=0;i<lcnt;i++)
{
out[i]=((hex2int(ucase(in[i*2]))&0xf)<<4);
out[i]+=hex2int(ucase(in[i*2+1]))&0xf;
icode=((int)out[i])&0xff;
out[i]^=((_edi & 0xffff)>>8);
_edi=(((_edi+icode)* 0xce6d)&0xffff)+0x58bf;
}
out[lcnt]=(char)0;//'\0';
return 1;
}



int EncodeGate(char *in, char *out)
{
int lcnt=strlen(in) ;
int i=0;
int icode=0;
int tcode=0;
int hbyte=0;
int lbyte=0;
int _edi=0xf667;
for(i=0;i<lcnt;i++)
{
icode=((int)in[i])&0xff;
tcode=icode;
tcode^=((_edi&0xffff)>>8);
hbyte=(tcode&0xf0)>>4;
lbyte=(tcode&0xf);
out[i*2]=int2hex(hbyte);
out[i*2+1]=int2hex(lbyte);
_edi=(((_edi+tcode)*0xce6d)&0xffff)+0x58bf;
}
out[i * 2] = '\0';
return 1;
}
...全文
120 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
JeraChen 2004-07-23
  • 打赏
  • 举报
回复
给分拉
linzhengqun 2004-07-22
  • 打赏
  • 举报
回复
function DecodeGate(var tin,tout:pchar):integer;
var lcnt,i,icode,_edi:integer;
begin
if tin=nil then begin result:=0;exit; end;
lcnt:=strlen(tin) shr 1;
if lcnt=0 then begin result:=0;exit; end;
if tin[0]=chr(0) then begin result:=0;exit; end;
i:=0;
icode:=0;
_edi:=$f667;
for i:=0 to lcnt-1 do
begin
tout[i]:=chr((ord(upcase(tin[i*2])) and $f)shl 4);
tout[i]:=chr(ord(tout[i])+ord(upcase(tin[i*2+1]))and $f);
icode:=ord(tout[i])and $ff;
tout[i]:=chr(ord(tout[i]) xor (_edi and $ffff) shr 8);
_edi:=(((_edi+icode)*$ce6d)and $ffff)+$58bf;
end;
tout[lcnt]:=chr(0);
result:=1;
end;
JeraChen 2004-07-22
  • 打赏
  • 举报
回复
TO: niniu(你牛)
晕哦,你比我改的还少啊~~
下面是我改的代码,但是加密的结果都是一样,请再帮我看看好吗?
function EncodeGate(var sin:Pchar):String;
var
lcnt:integer;
i:integer;
icode,tcode,hbyte,lbyte,_edi:integer;
MyStr:String[255];
begin
lcnt:=length(sin);
// setlength(sin,lcnt);
i:=0;

icode:=0;
tcode:=0;
hbyte:=0;
lbyte:=0;
_edi:=$f667;

for i:=0 to lcnt-1 do
begin
icode:=ord(sin[i]) and $ff;
tcode:=icode;
tcode:=tcode xor ((_edi and $ffff) shr 8); // tcode^=((_edi&0xffff)>>8);
hbyte:=(tcode and $f0) shr 4;
lbyte:=(tcode and $f);
MyStr[i*2]:=chr(hbyte);
MyStr[i*2+1]:=chr(lbyte);
_edi:=(((_edi+tcode)*$ce6d) and $ffff)+$58bf;
end;
// sout[i * 2] :=null;
result :=MyStr;
end;
fsybaby 2004-07-22
  • 打赏
  • 举报
回复
对指针不熟悉
myy 2004-07-21
  • 打赏
  • 举报
回复
偶尔干干体力活......
niniu 2004-07-21
  • 打赏
  • 举报
回复
function DecodeGate(var in,out: PChar): Integer;
var
lcnt,i,icode,_edt : Integer;
begin
if in = Nil then DecodeGate := 0;
lcnt := Length(in) shr 1;
if lcnt =0 then DecodeGate := 0;
if in[0]==char(0) then DecodeGate := 0;
i := 0;
icode := 0;


_edi := $f667;
for i := 0 to lcnt-1 do
begin
out[i] := //自己补充吧;
Inc(out[i],xx)//自己补充吧,xx = hex2int(ucase(in[i*2+1]))&0xf;
icode := (Integer(out[i]) and $ff;
out[i] := (_edi and $ffff)shr8;
_edi := (((_edi+icode)* $ce6d) and $ffff)+$58bf;

end;
out[lcnt]=char(0);//'\0';
result := 1;
end;
JeraChen 2004-07-21
  • 打赏
  • 举报
回复
没人会吗?

5,378

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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