des.c
static char *des(char *msg, char *k56, KeyRot k_func) {
    char *ct = des_permute(msg, IP, 64);
    char *result = NULL;
    if (ct != NULL) {
        for (int i = 1; i <= 16; i++) {
            k_func(k56, i);     //56-bit key rotation
            char *k48 = des_permute(k56, PC2, 48);   //current 48bit subkey
            if (k48 != NULL) {
                char *ffunc = f_func(ct + 32, k48);
                if (ffunc != NULL) {
                    char temp = ct[32];
                    ct[32] = '\0';
                    bstr_xor(ct, ffunc);    //xor left with f-func
                    ct[32] = temp;
                    bstr_swap(ct);          //swap left and right
                    free(ffunc);
                }
                free(k48);
            }
        }
        bstr_swap(ct);
        result = des_permute(ct, IP_INV, 64);
        free(ct);
    }
    return result;
}
/**
 * Encrypts or decrypts the message based on the passed in key rotation 
 * function pointer. Give a 64-bit message and a 56-bit key, this function 
 * will encrypt or decrypt the specified message. The result will be stored 
 * on the heap. This function will not perform any error check to increase 
 * efficiency. If any memory error occurred, NULL will be returned. 
 *
 * PARAMETERS: 
 * msg    - the 64-bit message to encrypt/decrypt
 * k56    - the 56-bit key used
 * k_func - the key rotation function, depending on encryption or 
 *          decryption
 *
 * RETURNS: 
 * The encrypted/decrypted text, or NULL if any error occurred. 
 */
Encrypts or decrypts the message based on the passed in key rotation
function pointer. Give a 64-bit message and a 56-bit key, this function
will encrypt or decrypt the specified message. The result will be stored
on the heap. This function will not perform any error check to increase
efficiency. If any memory error occurred, NULL will be returned.



The encrypted/decrypted text, or NULL if any error occurred.
Encrypts or decrypts the message based on the passed in key rotation function pointer . Give a 64 - bit message and a 56 - bit key this function will encrypt or decrypt the specified message . The result will be stored on the heap . This function will not perform any error check to increase efficiency . If any memory error occurred NULL will be returned . The encrypted / decrypted text or NULL if any error occurred .
static char *des(char *msg, char *k56, KeyRot k_func) {
    char *ct = des_permute(msg, IP, 64);
    char *result = NULL;
    if (ct != NULL) {
        for (int i = 1; i <= 16; i++) {
            k_func(k56, i);     
            char *k48 = des_permute(k56, PC2, 48);   
            if (k48 != NULL) {
                char *ffunc = f_func(ct + 32, k48);
                if (ffunc != NULL) {
                    char temp = ct[32];
                    ct[32] = '\0';
                    bstr_xor(ct, ffunc);    
                    ct[32] = temp;
                    bstr_swap(ct);          
                    free(ffunc);
                }
                free(k48);
            }
        }
        bstr_swap(ct);
        result = des_permute(ct, IP_INV, 64);
        free(ct);
    }
    return result;
}
static char * des ( char * msg , char * k56 , KeyRot k_func ) { char * ct = des_permute ( msg , IP , 64 ) ; char * result = NULL ; if ( ct != NULL ) { for ( int i = 1 ; i <= 16 ; i ++ ) { k_func ( k56 , i ) ; char * k48 = des_permute ( k56 , PC2 , 48 ) ; if ( k48 != NULL ) { char * ffunc = f_func ( ct + 32 , k48 ) ; if ( ffunc != NULL ) { char temp = ct [ 32 ] ; ct [ 32 ] = ' \0 ' ; bstr_xor ( ct , ffunc ) ; ct [ 32 ] = temp ; bstr_swap ( ct ) ; free ( ffunc ) ; } free ( k48 ) ; } } bstr_swap ( ct ) ; result = des_permute ( ct , IP_INV , 64 ) ; free ( ct ) ; } return result ; }
Encrypts or decrypts the message based on the passed in key rotation
 function pointer.
Encrypts or decrypts the message based on the passed in key rotation function pointer .
//56-bit key rotation //current 48bit subkey //xor left with f-func //swap left and right