Crypto/DEScpp/DES.cpp
/*-----------------------------------------------------------------------------
This function performs a DES encryption or decryption on a single 64-bit block
of data, using the specified 56-bit key. The data and key are packed one bit
per byte. Every element of data[] must be either 0 or 1. The results
will be highly anomalous if this is not the case.

The encrypted or decrypted data is returned to the data[] buffer.
-----------------------------------------------------------------------------*/
This function performs a DES encryption or decryption on a single 64-bit block
of data, using the specified 56-bit key. The data and key are packed one bit
per byte. Every element of data[] must be either 0 or 1. The results
will be highly anomalous if this is not the case.

The encrypted or decrypted data is returned to the data[] buffer.
This function performs a DES encryption or decryption on a single 64 - bit block of data using the specified 56 - bit key . The data and key are packed one bit per byte . Every element of data [] must be either 0 or 1 . The results will be highly anomalous if this is not the case . The encrypted or decrypted data is returned to the data [] buffer .
void des::encrypt_decrypt(unsigned char data[DES_DATA_SIZE],
  int  encrypt)
{
  unsigned char sbuffer[DES_SBUFFER_SIZE];
  union pbuffer_tag
  {
    unsigned char byte[DES_DATA_SIZE/2];
    DWORD dword[DES_DATA_SIZE/8];
  } pbuffer;
  for (int round = 0; round < DES_ROUNDS; round++)
  {
    {
      int i;
      for (i = 0; i < DES_SBUFFER_SIZE; i++)
      {
        sbuffer[i] = data[DES_DATA_SIZE/2 + EXPANSION_PERMUTATION[i]-1] ^
          compressed_shifted_key[encrypt ? round : 15-round][i];
      }
    }
    {
#define index(n) (sbuffer[n]<<5+2 | sbuffer[n+5]<<4+2 | \
        sbuffer[n+1]<<3+2 | sbuffer[n+2]<<2+2 | sbuffer[n+3]<<1+2 | \
        sbuffer[n+4]<<0+2)
      pbuffer.dword[0] = * (DWORD *) (MODIFIED_SBOX_1 + index(0));
      pbuffer.dword[1] = * (DWORD *) (MODIFIED_SBOX_2 + index(6));
      pbuffer.dword[2] = * (DWORD *) (MODIFIED_SBOX_3 + index(12));
      pbuffer.dword[3] = * (DWORD *) (MODIFIED_SBOX_4 + index(18));
      pbuffer.dword[4] = * (DWORD *) (MODIFIED_SBOX_5 + index(24));
      pbuffer.dword[5] = * (DWORD *) (MODIFIED_SBOX_6 + index(30));
      pbuffer.dword[6] = * (DWORD *) (MODIFIED_SBOX_7 + index(36));
      pbuffer.dword[7] = * (DWORD *) (MODIFIED_SBOX_8 + index(42));
    }
    if (round < 15)
    {
      int i;
      for (i = 0; i < DES_DATA_SIZE/2; i++)
      {
        unsigned char x = data[DES_DATA_SIZE/2 + i];
        data[DES_DATA_SIZE/2 + i] = data[i] ^ pbuffer.byte[PBOX_PERMUTATION[i]-1];
        data[i] = x;
      }
    }
    else
    {
      int i;
      for (i = 0; i < DES_DATA_SIZE/2; i++)
        data[i] = data[i] ^ pbuffer.byte[PBOX_PERMUTATION[i]-1];
    }
  }
}
void des :: encrypt_decrypt ( unsigned char data [ DES_DATA_SIZE ] , int encrypt ) { unsigned char sbuffer [ DES_SBUFFER_SIZE ] ; union pbuffer_tag { unsigned char byte [ DES_DATA_SIZE / 2 ] ; DWORD dword [ DES_DATA_SIZE / 8 ] ; } pbuffer ; for ( int round = 0 ; round < DES_ROUNDS ; round ++ ) { { int i ; for ( i = 0 ; i < DES_SBUFFER_SIZE ; i ++ ) { sbuffer [ i ] = data [ DES_DATA_SIZE / 2 + EXPANSION_PERMUTATION [ i ] - 1 ] ^ compressed_shifted_key [ encrypt ? round : 15 - round ] [ i ] ; } } { #define index ( n )  (sbuffer[n]<<5+2 | sbuffer[n+5]<<4+2 | \
        sbuffer[n+1]<<3+2 | sbuffer[n+2]<<2+2 | sbuffer[n+3]<<1+2 | \
        sbuffer[n+4]<<0+2) pbuffer . dword [ 0 ] = * ( DWORD * ) ( MODIFIED_SBOX_1 + index ( 0 ) ) ; pbuffer . dword [ 1 ] = * ( DWORD * ) ( MODIFIED_SBOX_2 + index ( 6 ) ) ; pbuffer . dword [ 2 ] = * ( DWORD * ) ( MODIFIED_SBOX_3 + index ( 12 ) ) ; pbuffer . dword [ 3 ] = * ( DWORD * ) ( MODIFIED_SBOX_4 + index ( 18 ) ) ; pbuffer . dword [ 4 ] = * ( DWORD * ) ( MODIFIED_SBOX_5 + index ( 24 ) ) ; pbuffer . dword [ 5 ] = * ( DWORD * ) ( MODIFIED_SBOX_6 + index ( 30 ) ) ; pbuffer . dword [ 6 ] = * ( DWORD * ) ( MODIFIED_SBOX_7 + index ( 36 ) ) ; pbuffer . dword [ 7 ] = * ( DWORD * ) ( MODIFIED_SBOX_8 + index ( 42 ) ) ; } if ( round < 15 ) { int i ; for ( i = 0 ; i < DES_DATA_SIZE / 2 ; i ++ ) { unsigned char x = data [ DES_DATA_SIZE / 2 + i ] ; data [ DES_DATA_SIZE / 2 + i ] = data [ i ] ^ pbuffer . byte [ PBOX_PERMUTATION [ i ] - 1 ] ; data [ i ] = x ; } } else { int i ; for ( i = 0 ; i < DES_DATA_SIZE / 2 ; i ++ ) data [ i ] = data [ i ] ^ pbuffer . byte [ PBOX_PERMUTATION [ i ] - 1 ] ; } } }
This function performs a DES encryption or decryption on a single 64-bit block
of data, using the specified 56-bit key.
This function performs a DES encryption or decryption on a single 64 - bit block of data using the specified 56 - bit key .
/* boolean */ /* XOR compressed key with expanded right half of data */ /* S-Box substitutions */ /* XOR and swap */