【问题标题】:How can I check the parity of a DES key?如何检查 DES 密钥的奇偶性?
【发布时间】:2011-11-01 06:32:02
【问题描述】:

我正在我的密码学课程中研究 DES(数据加密标准)算法,作为其中的一部分,我必须编写一个 C 代码,其中包含一个检查 DES 密钥奇偶性的函数。

我该怎么做?

【问题讨论】:

    标签: c cryptography des


    【解决方案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,但应该很容易翻译。

    【讨论】:

    • 非常感谢!该代码对我来说非常容易理解..只是我尝试时没有得到它的逻辑..下次发布此类问题之前会考虑更多!
    猜你喜欢
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2018-06-09
    • 1970-01-01
    相关资源
    最近更新 更多