A single DES key is 64 bits (8 bytes) long, however the actual key material used by the DES algorithm amounts to only 56 bits in length. The least significant bit of each byte is a parity bit, and should be set such that there is always an odd number of bits set (1’s) in each key byte. Only the 7 most significant bits of each byte are effective for security purposes.
Hence, DES has an effective key strength of 56 bits and TripleDES variants EDE2 and EDE3 have effective key strengths of 112 bits and 168 bits respectively.
The parity of a single DES key can be checked and adjusted using the following function:-
bool AdjustDESKeyParity(UCHAR* pucKey, int nKeyLen)
for(int i = 0; i < nKeyLen; i++)
cPar = 0;
for(int j = 0; j < DES::BLOCKSIZE; j++)
if(pucKey[i] & (0x01 << j))
cPar = !cPar;
pucKey[i] ^= 0x01;