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;
}
{
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;
}
解决方案 »
- 请问如何把Memo里的每一行内容转换为2进制然后存入TMemoryStream里?谢谢
- 请教大家 ADO+SQL 查询问题 谢谢 在线等结果!!
- 谁有InstallShield6。X的电子书籍呀
- 在针式打印机中如何通过编程控制打印机的进纸和退纸
- Delphi一般安装,有些控件的帮助没有,怎么把获取这些帮助?
- 请教在线程中用TUpdateSQL,Query组件实现数据库的缓存更新。急!!!
- Delphi 与Excel
- ***********为什么有的USE的单元,按住CTRL键跳到该单元去?******************
- Delphi文件读取:如何读取指定的几行?
- 老狼,拿命来!!!
- delphi中,如何设置窗体的背景图片?小弟找不到该属性...
- 程序中如何调用其他的执行程序和终止开启的程序?
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;
晕哦,你比我改的还少啊~~
下面是我改的代码,但是加密的结果都是一样,请再帮我看看好吗?
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;
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;