c - 如何检查 DES key 的奇偶校验?

标签 c cryptography des

我正在密码学类(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/

相关文章:

c++ - c++ 中的 read() 函数类似于 c read()

windows - 加密NG : Exporting RSA key with BCryptExportKey fails with STATUS_INVALID_HANDLE

java - 三重 DES 加密字符串生成 "\n"

c - 确定性方式生成 char 数组

c - 如何正确使用c中的线程和套接字?

c - 我将如何使用此 void 函数来计算百分比?

c++ - 在 Crypto++ 中使用 Curve25519 签名

macos - 如何在 Mac OS X 中的 bash 中创建 md5 哈希

java - ssl在java中可以一键加解密吗

c# - C/C++/C#中的DES实现