大家看一下这样的用法在window下的c++编程,是否合法(这是linuix下可编译的程序)
如果在windows下不合法,我该怎么办,大家给个建议,(主要是decrypt_every_8_byte(void)这个函数既要用到decryt的参数,和在decryt里定义变量)int decrypt(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; int decrypt_every_8_byte(void) {   ////////////////大家注意这里 这是个函数说明
for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte++) {
if (context_start + pos_in_byte >= instrlen)
return 1;
decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];
}
qq_decipher((unsigned long *) decrypted, (unsigned long *) key, (unsigned long *) decrypted); context_start += 8;
crypt_buff += 8;
pos_in_byte = 0;
return 1;
} // decrypt_every_8_byte 在这里结束 // at least 16 bytes and %8 == 0
if ((instrlen % 8) || (instrlen < 16))
return 0;
// get information from header
qq_decipher((unsigned long *) instr, (unsigned long *) key, (unsigned long *) 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 stuff 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;
}
} // 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;
}
} // 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;
}
} // for
return 1;
} // decrypt 整个函数在这里结束

解决方案 »

  1.   

    int decrypt_every_8_byte(void) // 你为什么把这个函数的定义 放在int decrypt这个函数里面???? 就是为了pos_in_byte 这些变量使用方便?? 楼住还是换个方式吧 不然好难看函数声明还是函数说明??? 好象不可以放在自定义的里面吧
      

  2.   

    大家要注意到,decrypt_every_8_byte()用到的不仅仅是pos_in_byte,几乎前面定义的变量都用到了,还有decrpt的参数!大家说最好怎么办?