How can I check the parity of a DES key?

寵の児 提交于 2020-01-26 04:24:09

问题


I am working on the DES (Data Encryption Standard) algorithm in my Cryptography class, as a part of which I have to write a C code which includes a function to check the parity of a DES key.

How can I do this?


回答1:


I would just do a Google search, and pick one of the first results that comes up.

Taken from the above link:

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;
}

This isn't pure C, but it should be easy enough to translate.



来源:https://stackoverflow.com/questions/7149944/how-can-i-check-the-parity-of-a-des-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!