dht-example.c
void
dht_hash(void *hash_return, int hash_size,
         const void *v1, int len1,
         const void *v2, int len2,
         const void *v3, int len3)
{
    const char *c1 = v1, *c2 = v2, *c3 = v3;
    char key[9];                /* crypt is limited to 8 characters */
    int i;

    memset(key, 0, 9);
#define CRYPT_HAPPY(c) ((c % 0x60) + 0x20)

    for(i = 0; i < 2 && i < len1; i++)
        key[i] = CRYPT_HAPPY(c1[i]);
    for(i = 0; i < 4 && i < len1; i++)
        key[2 + i] = CRYPT_HAPPY(c2[i]);
    for(i = 0; i < 2 && i < len1; i++)
        key[6 + i] = CRYPT_HAPPY(c3[i]);
    strncpy(hash_return, crypt(key, "jc"), hash_size);
}
/* But for this toy example, we might as well use something weaker. */
But for this toy example, we might as well use something weaker.
But for this toy example we might as well use something weaker .
void
dht_hash(void *hash_return, int hash_size,
         const void *v1, int len1,
         const void *v2, int len2,
         const void *v3, int len3)
{
    const char *c1 = v1, *c2 = v2, *c3 = v3;
    char key[9];                
    int i;
    memset(key, 0, 9);
#define CRYPT_HAPPY(c) ((c % 0x60) + 0x20)
    for(i = 0; i < 2 && i < len1; i++)
        key[i] = CRYPT_HAPPY(c1[i]);
    for(i = 0; i < 4 && i < len1; i++)
        key[2 + i] = CRYPT_HAPPY(c2[i]);
    for(i = 0; i < 2 && i < len1; i++)
        key[6 + i] = CRYPT_HAPPY(c3[i]);
    strncpy(hash_return, crypt(key, "jc"), hash_size);
}
void dht_hash ( void * hash_return , int hash_size , const void * v1 , int len1 , const void * v2 , int len2 , const void * v3 , int len3 ) { const char * c1 = v1 , * c2 = v2 , * c3 = v3 ; char key [ 9 ] ; int i ; memset ( key , 0 , 9 ) ; #define CRYPT_HAPPY ( c )  ((c % 0x60) + 0x20) for ( i = 0 ; i < 2 && i < len1 ; i ++ ) key [ i ] = CRYPT_HAPPY ( c1 [ i ] ) ; for ( i = 0 ; i < 4 && i < len1 ; i ++ ) key [ 2 + i ] = CRYPT_HAPPY ( c2 [ i ] ) ; for ( i = 0 ; i < 2 && i < len1 ; i ++ ) key [ 6 + i ] = CRYPT_HAPPY ( c3 [ i ] ) ; strncpy ( hash_return , crypt ( key , " " ) , hash_size ) ; }
But for this toy example, we might as well use something weaker.
But for this toy example we might as well use something weaker .
/* crypt is limited to 8 characters */