哪位高手帮忙把C翻译成delphi,多谢int qqdecrypt( unsigned char* instr, int instrlen, unsigned char* key,
unsigned char* outstr, int* outstrlen_ptr)
{
unsigned char
decrypted[8], m[8],
* crypt_buff,
* crypt_buff_pre_8,
* outp;
int
count,
context_start,
pos_in_byte,
padding;#define decrypt_every_8_byte() {\
char bNeedRet = 0;\
for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte ++ ) {\
if (context_start + pos_in_byte >= instrlen) \
{\
bNeedRet = 1;\
break;\
}\
decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];\
}\
if( !bNeedRet ) { \
decipher( (unsigned int *) decrypted, \
(unsigned int *) key, \
(unsigned int *) decrypted);\
\
context_start += 8;\
crypt_buff += 8;\
pos_in_byte = 0;\
}\
}/* decrypt_every_8_byte*/ /* at least 16 bytes and %8 == 0*/
if ((instrlen % 8) || (instrlen < 16)) return 0;
/* get information from header*/
decipher( (unsigned int *) instr,
(unsigned int *) key,
(unsigned int *) decrypted);
pos_in_byte = decrypted[0] & 0x7;
count = instrlen - pos_in_byte - 10; /* this is the plaintext length*/
/* return if outstr buffer is not large enought or error plaintext length*/
if (*outstrlen_ptr < count || count < 0) return 0; memset(m, 0, 8);
crypt_buff_pre_8 = m;
*outstrlen_ptr = count; /* everything is ok! set return string length*/ crypt_buff = instr + 8; /* address of real data start */
context_start = 8; /* context is at the second 8 byte*/
pos_in_byte ++; /* start of paddng stuffv*/ padding = 1; /* at least one in header*/
while (padding <= 2) { /* there are 2 byte padding stuff in header*/
if (pos_in_byte < 8) { /* bypass the padding stuff, none sense data*/
pos_in_byte ++; padding ++;
}
if (pos_in_byte == 8) {
crypt_buff_pre_8 = instr;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* while*/ outp = outstr;
while(count !=0) {
if (pos_in_byte < 8) {
*outp = crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte];
outp ++;
count --;
pos_in_byte ++;
}
if (pos_in_byte == 8) {
crypt_buff_pre_8 = crypt_buff - 8;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* while*/
for (padding = 1; padding < 8; padding ++) {
if (pos_in_byte < 8) {
if (crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte]) {
return 0;
}
pos_in_byte ++;
}
if (pos_in_byte == 8 ) {
crypt_buff_pre_8 = crypt_buff;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* for*/
return 1;}
unsigned char* outstr, int* outstrlen_ptr)
{
unsigned char
decrypted[8], m[8],
* crypt_buff,
* crypt_buff_pre_8,
* outp;
int
count,
context_start,
pos_in_byte,
padding;#define decrypt_every_8_byte() {\
char bNeedRet = 0;\
for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte ++ ) {\
if (context_start + pos_in_byte >= instrlen) \
{\
bNeedRet = 1;\
break;\
}\
decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];\
}\
if( !bNeedRet ) { \
decipher( (unsigned int *) decrypted, \
(unsigned int *) key, \
(unsigned int *) decrypted);\
\
context_start += 8;\
crypt_buff += 8;\
pos_in_byte = 0;\
}\
}/* decrypt_every_8_byte*/ /* at least 16 bytes and %8 == 0*/
if ((instrlen % 8) || (instrlen < 16)) return 0;
/* get information from header*/
decipher( (unsigned int *) instr,
(unsigned int *) key,
(unsigned int *) decrypted);
pos_in_byte = decrypted[0] & 0x7;
count = instrlen - pos_in_byte - 10; /* this is the plaintext length*/
/* return if outstr buffer is not large enought or error plaintext length*/
if (*outstrlen_ptr < count || count < 0) return 0; memset(m, 0, 8);
crypt_buff_pre_8 = m;
*outstrlen_ptr = count; /* everything is ok! set return string length*/ crypt_buff = instr + 8; /* address of real data start */
context_start = 8; /* context is at the second 8 byte*/
pos_in_byte ++; /* start of paddng stuffv*/ padding = 1; /* at least one in header*/
while (padding <= 2) { /* there are 2 byte padding stuff in header*/
if (pos_in_byte < 8) { /* bypass the padding stuff, none sense data*/
pos_in_byte ++; padding ++;
}
if (pos_in_byte == 8) {
crypt_buff_pre_8 = instr;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* while*/ outp = outstr;
while(count !=0) {
if (pos_in_byte < 8) {
*outp = crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte];
outp ++;
count --;
pos_in_byte ++;
}
if (pos_in_byte == 8) {
crypt_buff_pre_8 = crypt_buff - 8;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* while*/
for (padding = 1; padding < 8; padding ++) {
if (pos_in_byte < 8) {
if (crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte]) {
return 0;
}
pos_in_byte ++;
}
if (pos_in_byte == 8 ) {
crypt_buff_pre_8 = crypt_buff;
//if (! decrypt_every_8_byte()) return 0;
decrypt_every_8_byte();
}
}/* for*/
return 1;}
解决方案 »
- Delphi中使用OLE方法操作Excel--如何让导出的Excel第一列的属性为文本类型?
- 想找一个南京的朋友完善一个小项目
- 24位的bmp图像如何转换为16位的?100分,解决问题者再送100分.高手来帮忙,低手来试试.结贴率100%的哦
- 【再转贴一文】电子邮件头全揭密:)
- 请问DELPHI5+PRODOX7如何批量删除数据库中的记录?
- 语句错误!急用
- 英文Delphi写的程序怎么显示日语?
- 请教ADOQuery1.ExecSQL与ADOQuery1.Open有什么区别?还有...
- 关于DBGRID的使用?
- 内存地址和指针的问题,pascal高手请回答
- UDP端口与QQ端口号
- 【泰坦散分贴】突然发现宝宝今天半岁了,高兴,散分!!!!!!
编译成DLL吧
我自己也是个懒人