des.c
static char *f_func(char *r, char *k48) {
    char *expanded = des_permute(r, EXP, 48);    //expansion to 48 bits
    if (expanded == NULL)
        return NULL;

    bstr_xor(expanded, k48);
    int r_index = 0;            //store current index of r for sbox index
    int fill_index = 0;         //store current index of r for filling bits
    for (int i = 0; i < 8; i++) {
        char *sbox_bin = sbox_value(expanded + r_index, i);
        memcpy(expanded + fill_index, sbox_bin, 4 * sizeof(char));
        r_index += 6;           //original separates by 6-bit chunk
        fill_index += 4;        //result separates by 4-bit chunk
    }
    expanded[32] = '\0';

    char *result = des_permute(expanded, P, 32);
    free(expanded);
    return result;
}
/**
 * The f-function for DES. Takes in a 32-bit message (the right half) 
 * and a key of 48 bits, outputs a 32-bit block used to XOR the left 
 * half. For efficiency reasons, this function will not perform any 
 * error checking. Returns the 32-bit result, or NULL if any memory 
 * error occurred. 
 * 
 * PARAMETERS: 
 * r - the 32-bit block
 * k - the 48-bit key
 *
 * RETURNS: 
 * The 32-bit result, or NULL if any error occurred. 
 */
The f-function for DES. Takes in a 32-bit message (the right half)
and a key of 48 bits, outputs a 32-bit block used to XOR the left
half. For efficiency reasons, this function will not perform any
error checking. Returns the 32-bit result, or NULL if any memory
error occurred.

the 32-bit block
k - the 48-bit key

The 32-bit result, or NULL if any error occurred.
The f - function for DES . Takes in a 32 - bit message ( the right half ) and a key of 48 bits outputs a 32 - bit block used to XOR the left half . For efficiency reasons this function will not perform any error checking . Returns the 32 - bit result or NULL if any memory error occurred . the 32 - bit block k - the 48 - bit key The 32 - bit result or NULL if any error occurred .
static char *f_func(char *r, char *k48) {
    char *expanded = des_permute(r, EXP, 48);    
    if (expanded == NULL)
        return NULL;
    bstr_xor(expanded, k48);
    int r_index = 0;            
    int fill_index = 0;         
    for (int i = 0; i < 8; i++) {
        char *sbox_bin = sbox_value(expanded + r_index, i);
        memcpy(expanded + fill_index, sbox_bin, 4 * sizeof(char));
        r_index += 6;           
        fill_index += 4;        
    }
    expanded[32] = '\0';
    char *result = des_permute(expanded, P, 32);
    free(expanded);
    return result;
}
static char * f_func ( char * r , char * k48 ) { char * expanded = des_permute ( r , EXP , 48 ) ; if ( expanded == NULL ) return NULL ; bstr_xor ( expanded , k48 ) ; int r_index = 0 ; int fill_index = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { char * sbox_bin = sbox_value ( expanded + r_index , i ) ; memcpy ( expanded + fill_index , sbox_bin , 4 * sizeof ( char ) ) ; r_index += 6 ; fill_index += 4 ; } expanded [ 32 ] = ' \0 ' ; char * result = des_permute ( expanded , P , 32 ) ; free ( expanded ) ; return result ; }
The f-function for DES.
The f - function for DES .
//expansion to 48 bits //store current index of r for sbox index //store current index of r for filling bits //original separates by 6-bit chunk //result separates by 4-bit chunk