如何检查DES密钥的奇偶校验? [英] How can I check the parity of a DES key?
本文介绍了如何检查DES密钥的奇偶校验?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究密码学类中的DES(数据加密标准)算法,作为其中一部分,我必须编写一个C代码,其中包括一个用于检查DES密钥奇偶校验的函数。
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.
我该怎么做?
推荐答案
我只会做 Google搜索,然后选择出现的第一个结果之一。
来自上面的链接:
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语言,但翻译起来应该很容易。
This isn't pure C, but it should be easy enough to translate.
这篇关于如何检查DES密钥的奇偶校验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文