帮忙看一个加密函数
taft 2004-08-22 03:26:05 void encrypt (
unsigned char* instr,
int instrlen,
unsigned char* key,
unsigned char* outstr,
int* outstrlen_prt)
{
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
int rand(void) { // it can be the real random seed function
return 0xdead; } // override with number, convenient for debug
/*** we encrypt every eight byte ***/
void encrypt_every_8_byte (void) {
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 long *) plain,
(unsigned long *) key,
(unsigned long *) 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] = (rand() & 0xf8) | pos_in_byte;
memset(plain+1, rand()&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++] = rand() & 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_prt = count;
}
怎么这个加密函数内包含了2个函数定义,我linux下编译成功,但在vc下就是不行。程序的流程是什么?我该怎么在外部特别是实现第2个嵌套的函数encrypt_every_8_byte (),里面的变量太麻烦了。