des.c
char *des_permute(char *str, const int p[], size_t len) {
    size_t oldlen = bstr_len(str);
    if (oldlen == 0 || len == 0 || p == NULL)
        return NULL;

    char *new = malloc((len + 1) * (sizeof *new));
    if (new != NULL) {
        new[len] = '\0';
        for (size_t i = 0; i < len; i++) {
            if ((p[i] - 1) > oldlen) {
                free(new);      //an element is out of bound
                return NULL;
            }
            new[i] = str[p[i] - 1];
        }
    }
    return new;
}
/**
 * Permutes the specified bit string using the given permutation and length. 
 * Returns the result bit string after the permutation (dynamically 
 * allocated). If any error occurred during permutation process, NULL will 
 * be returned. 
 *
 * PARAMETERS: 
 * str - the bit string to permute
 * p   - the permutation mapping
 * len - the length of the permutation mapping
 *
 * RETURNS: 
 * The permutated bit string, or NULL if any error occurred. 
 */
Permutes the specified bit string using the given permutation and length.
Returns the result bit string after the permutation (dynamically
allocated). If any error occurred during permutation process, NULL will
be returned.

the bit string to permute
p   - the permutation mapping
len - the length of the permutation mapping

The permutated bit string, or NULL if any error occurred.
Permutes the specified bit string using the given permutation and length . Returns the result bit string after the permutation ( dynamically allocated ) . If any error occurred during permutation process NULL will be returned . the bit string to permute p - the permutation mapping len - the length of the permutation mapping The permutated bit string or NULL if any error occurred .
char *des_permute(char *str, const int p[], size_t len) {
    size_t oldlen = bstr_len(str);
    if (oldlen == 0 || len == 0 || p == NULL)
        return NULL;
    char *new = malloc((len + 1) * (sizeof *new));
    if (new != NULL) {
        new[len] = '\0';
        for (size_t i = 0; i < len; i++) {
            if ((p[i] - 1) > oldlen) {
                free(new);      
                return NULL;
            }
            new[i] = str[p[i] - 1];
        }
    }
    return new;
}
char * des_permute ( char * str , const int p [ ] , size_t len ) { size_t oldlen = bstr_len ( str ) ; if ( oldlen == 0 || len == 0 || p == NULL ) return NULL ; char * new = malloc ( ( len + 1 ) * ( sizeof * new ) ) ; if ( new != NULL ) { new [ len ] = ' \0 ' ; for ( size_t i = 0 ; i < len ; i ++ ) { if ( ( p [ i ] - 1 ) > oldlen ) { free ( new ) ; return NULL ; } new [ i ] = str [ p [ i ] - 1 ] ; } } return new ; }
Permutes the specified bit string using the given permutation and length.
Permutes the specified bit string using the given permutation and length .
//an element is out of bound