我正在密码学类(class)中研究 DES(数据加密标准)算法,作为其中的一部分,我必须编写一个 C 代码,其中包含一个检查 DES key 奇偶校验的函数。
我该怎么做?
最佳答案
我只想做 Google search ,然后选择 one of the first results that comes up .
取自上述链接:
bool AdjustDESKeyParity(UCHAR* pucKey, int nKeyLen)
{
int cPar;
for(int i = 0; i < nKeyLen; i++)
{
cPar = 0;
for(int j = 0; j < DES::BLOCKSIZE; j++)
{
if(pucKey[i] & (0×01 << j))
cPar = !cPar;
}
if(!cPar)
pucKey[i] ^= 0×01;
}
return true;
}
这不是纯 C 语言,但应该很容易翻译。
关于c - 如何检查 DES key 的奇偶校验?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149944/