哪位高手帮忙把C翻译成delphi,多谢 void qqencrypt( unsigned char* instr, int instrlen, unsigned char* key,
unsigned char*  outstr, int* outstrlen_ptr)
{
unsigned char 
plain[8],         /* plain text buffer*/
plain_pre_8[8],   /* plain text buffer, previous 8 bytes*/
* crypted,        /* crypted text*/
* crypted_pre_8,  /* crypted test, previous 8 bytes*/
* inp;            /* current position in instr*/
int 
pos_in_byte = 1,  /* loop in the byte */
is_header=1,      /* header is one byte*/
count=0,          /* number of bytes being crypted*/
padding = 0;      /* number of padding stuff*/ //void encrypt_every_8_byte (void);     /*** we encrypt every eight byte ***/
#define encrypt_every_8_byte()  \
{\
for(pos_in_byte=0; pos_in_byte<8; pos_in_byte++) {\
if(is_header) { plain[pos_in_byte] ^= plain_pre_8[pos_in_byte]; }\
else { plain[pos_in_byte] ^= crypted_pre_8[pos_in_byte]; }\
} /* prepare plain text*/\
encipher( (unsigned int *) plain,\
(unsigned int *) key, \
(unsigned int *) crypted);   /* encrypt it*/\
\
for(pos_in_byte=0; pos_in_byte<8; pos_in_byte++) {\
crypted[pos_in_byte] ^= plain_pre_8[pos_in_byte]; \
} \
memcpy(plain_pre_8, plain, 8);     /* prepare next*/\
\
crypted_pre_8   =   crypted;       /* store position of previous 8 byte*/\
crypted         +=  8;             /* prepare next output*/\
count           +=  8;             /* outstrlen increase by 8*/\
pos_in_byte     =   0;             /* back to start*/\
is_header       =   0;             /* and exit header*/\
}/* encrypt_every_8_byte*/ pos_in_byte = (instrlen + 0x0a) % 8; /* header padding decided by instrlen*/
if (pos_in_byte) { 
pos_in_byte = 8 - pos_in_byte; 
}
plain[0] = (random() & 0xf8) | pos_in_byte;

memset(plain+1, random()&0xff, pos_in_byte++);
memset(plain_pre_8, 0x00, sizeof(plain_pre_8)); crypted = crypted_pre_8 = outstr; padding = 1; /* pad some stuff in header*/
while (padding <= 2) { /* at most two byte */
if(pos_in_byte < 8) { plain[pos_in_byte++] = random() & 0xff; padding ++; } 
if(pos_in_byte == 8){ encrypt_every_8_byte(); } 
} inp = instr;
while (instrlen > 0) {
if (pos_in_byte < 8) { plain[pos_in_byte++] = *(inp++); instrlen --; }
if (pos_in_byte == 8){ encrypt_every_8_byte(); }
} padding = 1; /* pad some stuff in tailer*/
while (padding <= 7) { /* at most sever byte*/
if (pos_in_byte < 8) { plain[pos_in_byte++] = 0x00; padding ++; }
if (pos_in_byte == 8){ encrypt_every_8_byte(); }
}  *outstrlen_ptr = count;}

解决方案 »

  1.   

    把这个做成dll, 用delphi来调用就行了
      

  2.   

    呵呵回复错了。
    4楼的办法是最省事的办法了。
    如果改装的话,也不是很难,就是一个定义到另一个函数内部。
    就好了。
    变量也可以实现共享的。
    但我确实是没有时间呀。
    写个框架吧。
    procedure qqencrypt( var instr; integer instrlen; var key; 
    var  outstr; var int outstrlen_ptr) 
    var
    plain: array[0..7] of uchar;
    plain_pre_8: array[0..7] of uchar;
    crypted, crypted_pre_8: uchar;
    inp, pos_in_byte, is_header, count, padding : integer; 
    proecedure encrypt_every_8_byte()  
    begin
    pos_in_byte:=0;
    begin
    end;
    end;
      

  3.   

    没有mfc的话编译个dll吧。这样你也能熟悉下c++
    封装个dll就一会的功夫,楼主为何不试试呢!
      

  4.   

    4各月没碰delphi,发现生疏了好多
      

  5.   

    终于改好了,语法上我已测试,其它的你自己试试吧:
    procedure  qqencrypt(  instr:pbyte;  instrlen:integer;  key:pbyte; outstr:pbyte; outstrlen_ptr:pinteger);
    var
    plain:array [0..8] of byte;
    plain_pre_8:array [0..8] of byte;
    crypted:pbyte;
    crypted_pre_8:pbyte;
    inp:pbyte;
    pos_in_byte :integer;
    is_header:integer;
    count:integer;
    padding :integer;
    temp_ptr:pbyte;
    beginpos_in_byte := 1;   
    is_header:=1;       
    count:=0;           
    padding := 0;       
    pos_in_byte := (instrlen + $0a)  mod 8;
    if (pos_in_byte<>0)  then
    begin
    pos_in_byte := 8 - pos_in_byte;
    end ;plain[0] := (random(maxint) and $f8) or pos_in_byte;
    fillchar(plain[1],  pos_in_byte,integer(random(maxint)) and $ff);
    inc(pos_in_byte);
    fillchar(plain_pre_8,  sizeof(plain_pre_8),$0);
    crypted :=  outstr;
    crypted_pre_8 := outstr  ;
    padding := 1;
    while (padding <= 2)  do
    begin
       if(pos_in_byte < 8) then
       begin
           plain[pos_in_byte] :=integer(random(maxint)) and $ff;
           inc(pos_in_byte);
           inc(padding); 
        end;  
      if(pos_in_byte = 8) then
      begin
          for pos_in_byte:=0 to 7 do
          begin
             if(is_header<>0) then
             begin
                plain[pos_in_byte] := plain[pos_in_byte] xor plain_pre_8[pos_in_byte];
             end else 
             begin
                 temp_ptr:=crypted_pre_8;
                 inc( temp_ptr,pos_in_byte);
                 plain[pos_in_byte] :=plain[pos_in_byte] xor (temp_ptr)^;
             end;
           end;
           encipher(pword(@plain),pword( key),pword( crypted));
           for pos_in_byte:=0 to 7 do
           begin
            temp_ptr:=crypted;
            inc( temp_ptr,pos_in_byte);
            temp_ptr^ := temp_ptr^ xor plain_pre_8[pos_in_byte];
           end;
           move(plain_pre_8, plain, 8);
           crypted_pre_8 := crypted;
           inc(crypted ,8);
           count := count+8;
            pos_in_byte := 0; 
            is_header := 0;
          end;
       end;       
    inp := instr;
    while (instrlen > 0) do
    begin
       if (pos_in_byte < 8) then
       begin
          plain[pos_in_byte] := inp^;
          inc(inp);
          inc(pos_in_byte);
          dec(instrlen);
      end;
      if (pos_in_byte = 8) then
      begin
         for pos_in_byte:=0 to 7 do
         begin
            if(is_header<>0) then
            begin
               plain[pos_in_byte] :=plain[pos_in_byte] xor  plain_pre_8[pos_in_byte];
            end else
            begin
               temp_ptr:=crypted_pre_8;
               inc(temp_ptr,pos_in_byte);
               plain[pos_in_byte] := plain[pos_in_byte] xor temp_ptr^;
            end;
         end;
         encipher(pword(@plain),pword( key),pword( crypted));
         for pos_in_byte:=0 to 7 do
         begin
            temp_ptr:=crypted ;
            inc(temp_ptr,pos_in_byte );
            temp_ptr^ := temp_ptr^ xor plain_pre_8[pos_in_byte];
         end;
         move(plain_pre_8, plain, 8);
         crypted_pre_8 := crypted;
         inc(crypted , 8);
         count :=count+ 8;
         pos_in_byte := 0;
         is_header := 0;
      end;
    end;
    padding := 1;
    while (padding <= 7) do
    begin
       if (pos_in_byte < 8) then
       begin
          plain[pos_in_byte] := $0;
          inc(pos_in_byte);
          inc(padding) ;
       end;
       if (pos_in_byte = 8) then
       begin
          for pos_in_byte:=0 to 7 do
          begin
             if(is_header<>0) then
             begin
                plain[pos_in_byte] :=  plain[pos_in_byte] xor plain_pre_8[pos_in_byte];
             end else
             begin
               temp_ptr:=crypted_pre_8;
               inc(temp_ptr,pos_in_byte);
               plain[pos_in_byte] := plain[pos_in_byte] xor  temp_ptr^;
             end;
           end ;
           encipher(pword(@plain),pword( key),pword( crypted));
           for pos_in_byte:=0 to 7 do
           begin
              temp_ptr:=crypted;
              inc(temp_ptr,pos_in_byte);
              temp_ptr^ := temp_ptr^ xor  plain_pre_8[pos_in_byte];
           end ;
           move(plain_pre_8, plain, 8);
           crypted_pre_8 := crypted;
           inc(crypted, 8);
           count := count+8;
           pos_in_byte := 0;
          is_header := 0;
       end;
    end;
    outstrlen_ptr^ := count;
    end;