如何检查DES密钥的奇偶校验?

时间:2011-08-22 15:39:44

标签: c cryptography des

我正在使用我的密码术课程中的DES(数据加密标准)算法,作为其中的一部分,我必须编写一个C代码,其中包括检查DES密钥奇偶校验的函数。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我只需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,但它应该很容易翻译。