请各位指点以下C函数如何求逆运算,先谢啦!
C语言版的函数如下:
////////////////////////////////////////////////////////////////////////////////
// Parameter: pBuf, 4-byte long buf
void CalculateBuf(BYTE *pBuf)
{
BYTE bR16, bR17, bR18, bR19, bR20, bR21;
bR18 = pBuf[1] ^ pBuf[2] ^ pBuf[3];
bR19 = pBuf[0] ^ pBuf[2] ^ pBuf[3];
bR20 = pBuf[0] ^ pBuf[1] ^ pBuf[3];
bR21 = pBuf[1] ^ pBuf[2] ^ pBuf[0];
for (int i = 0; i < 4; i++)
{
if (pBuf[i] & 0x80)
{
bR16 = 0x1b;
}
else
{
bR16 = 0;
}
pBuf[i] <<= 1;
pBuf[i] ^= bR16;
}
////////////////////////////////////////////////////////////
bR18 ^= pBuf[0] ^ pBuf[1];
bR19 ^= pBuf[2] ^ pBuf[1];
bR20 ^= pBuf[2] ^ pBuf[3];
bR21 ^= pBuf[0] ^ pBuf[3];
///////// here repeat
for (i = 0; i < 4; i++)
{
if (pBuf[i] & 0x80)
{
bR16 = 0x1b;
}
else
{
bR16 = 0;
}
pBuf[i] <<= 1;
pBuf[i] ^= bR16;
}
bR18 ^= pBuf[2] ^ pBuf[0];
bR19 ^= pBuf[1] ^ pBuf[3];
bR20 ^= pBuf[2] ^ pBuf[0];
bR21 ^= pBuf[1] ^ pBuf[3];
///////////////////////here
for (i = 0; i < 4; i++)
{
if (pBuf[i] & 0x80)
{
bR16 = 0x1b;
}
else
{
bR16 = 0;
}
pBuf[i] <<= 1;
pBuf[i] ^= bR16;
}
bR17 = pBuf[0] ^ pBuf[1] ^ pBuf[2] ^ pBuf[3];
bR18 ^= bR17;
bR19 ^= bR17;
bR20 ^= bR17;
bR21 ^= bR17;
pBuf[0] = bR18;
pBuf[1] = bR19;
pBuf[2] = bR20;
pBuf[3] = bR21;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!