0

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?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129

1 Answers1

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.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • thank u very much !! The code is very much understandable to me..it's just that I wasn't getting the logic for it when I tried..will think more next time before posting such questions !! – Parth Doshi Aug 22 '11 at 15:52