des.c
static char *sbox_value(char *b, int sbox) {
    static char bin[] = "0000";
    bin[0] = bin[1] = bin[2] = bin[3] = '0';    //reset bits

    char row[] = { b[0], b[5], '\0' };
    char col[] = { b[1], b[2], b[3], b[4], '\0' };
    int sbox_index = 16 * strtol(row, NULL, 2) + strtol(col, NULL, 2);
    int sbox_val = SBOX[sbox][sbox_index];
    if (sbox_val > 15 || sbox_val < 0)
        return bin;     //sbox out of range, return 0000

    int i = 3;  //length index of bit string
    do {
        bin[i--] = (sbox_val & 1) + '0';
    } while ((sbox_val >>= 1) > 0);
    return bin;
}
/**
 * Retrieves the specified sbox value (4 bits) based on the input binary. 
 * The binary must be 6 bits or more in total. This function will not 
 * validate the input for increased performance. 
 *
 * PARAMETERS: 
 * b    - the binary to extract the sbox
 * sbox - the sbox to use, from 0 to 7
 *
 * RETURNS: 
 * The 4-bit s-box value binary that the specified input represents. 
 */
Retrieves the specified sbox value (4 bits) based on the input binary.
The binary must be 6 bits or more in total. This function will not
validate the input for increased performance.

b    - the binary to extract the sbox
sbox - the sbox to use, from 0 to 7

The 4-bit s-box value binary that the specified input represents.
Retrieves the specified sbox value ( 4 bits ) based on the input binary . The binary must be 6 bits or more in total . This function will not validate the input for increased performance . b - the binary to extract the sbox sbox - the sbox to use from 0 to 7 The 4 - bit s - box value binary that the specified input represents .
static char *sbox_value(char *b, int sbox) {
    static char bin[] = "0000";
    bin[0] = bin[1] = bin[2] = bin[3] = '0';    
    char row[] = { b[0], b[5], '\0' };
    char col[] = { b[1], b[2], b[3], b[4], '\0' };
    int sbox_index = 16 * strtol(row, NULL, 2) + strtol(col, NULL, 2);
    int sbox_val = SBOX[sbox][sbox_index];
    if (sbox_val > 15 || sbox_val < 0)
        return bin;     
    int i = 3;  
    do {
        bin[i--] = (sbox_val & 1) + '0';
    } while ((sbox_val >>= 1) > 0);
    return bin;
}
static char * sbox_value ( char * b , int sbox ) { static char bin [ ] = " " ; bin [ 0 ] = bin [ 1 ] = bin [ 2 ] = bin [ 3 ] = ' ' ; char row [ ] = { b [ 0 ] , b [ 5 ] , ' \0 ' } ; char col [ ] = { b [ 1 ] , b [ 2 ] , b [ 3 ] , b [ 4 ] , ' \0 ' } ; int sbox_index = 16 * strtol ( row , NULL , 2 ) + strtol ( col , NULL , 2 ) ; int sbox_val = SBOX [ sbox ] [ sbox_index ] ; if ( sbox_val > 15 || sbox_val < 0 ) return bin ; int i = 3 ; do { bin [ i -- ] = ( sbox_val & 1 ) + ' ' ; } while ( ( sbox_val >>= 1 ) > 0 ) ; return bin ; }
Retrieves the specified sbox value (4 bits) based on the input binary.
Retrieves the specified sbox value ( 4 bits ) based on the input binary .
//reset bits //sbox out of range, return 0000 //length index of bit string