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;
}

解决方案 »

  1.   

    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;
      

  2.   

    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;
      

  3.   

    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;