好的..我知道问这样的问题听起来很烦人,但我真的不明白下面的代码 [advance_reg(int*)]。在代码的注释中,它说“/寄存器根据原始多项式(64,4,3,1,0); /”,我只是没有得到它。有人请给我有关此代码的提示吗?例如,为什么它会这样定义 adv_64 数组?我理解第一个 for 块移动了 27 次,每次一位。但为什么?这背后的数学原理是什么?此外,为什么要执行第二个 for 块?这些都与多项式(64,4,3,1,0)有什么联系?
static int bitcnt( int x)
{
unsigned i=0,y;
for (y=(unsigned)x; y; y &= (y-1) )
i++;
return(i);
}
static void advance_reg(int *reg_fill)
{
const int mask = 0x1b;
int adv_64[4][2];
int i,new_fill[2];
unsigned temp;
adv_64[0][0] = 0xb0000000;
adv_64[0][1] = 0x1b;
adv_64[1][0] = 0x60000000;
adv_64[1][1] = 0x2d;
adv_64[2][0] = 0xc0000000;
adv_64[2][1] = 0x5a;
adv_64[3][0] = 0x80000000;
adv_64[3][1] = 0xaf;
new_fill[1] = new_fill[0] = 0;
temp = mask<<27;
for (i=27;i>=0;i--)
{
new_fill[0] = (new_fill[0]<<1) | (1&bitcnt(reg_fill[0]&temp));
new_fill[1] = (new_fill[1]<<1) | (1&bitcnt(reg_fill[1]&temp));
temp >>= 1;
}
for (i=28;i<32;i++)
{
temp = bitcnt(reg_fill[0]&(mask<<i));
temp ^= bitcnt(reg_fill[1]&(mask>>(32-i)));
new_fill[0] |= (1&temp)<<i;
temp = bitcnt(reg_fill[0]&adv_64[i-28][0]);
temp ^= bitcnt(reg_fill[1]&adv_64[i-28][1]);
new_fill[1] |= (1&temp)<<i;
}
reg_fill[0] = new_fill[0];
reg_fill[1] = new_fill[1];
}