2

The below integer "hash" functions form a pair of reversible hash functions:

uint32_t hash ( uint32_t x ) {

    x = ( ( x >> 16 ) ^ x ) * 0x45d9f3b;
    x = ( ( x >> 16 ) ^ x ) * 0x45d9f3b;
    x = ( ( x >> 16 ) ^ x );

    return x;
}

uint32_t unhash ( uint32_t x ) {

    x = ( ( x >> 16 ) ^ x ) * 0x119de1f3;
    x = ( ( x >> 16 ) ^ x ) * 0x119de1f3;
    x = ( ( x >> 16 ) ^ x );

    return x;
}

The reversibility obviously depends on the "magic values". In the case of uint32_t's, given 0x45d9f3b, the value 0x119de1f3 can be easily found by exhaustive search.

I would like to design a 64-bit equivalent. Exhaustive search is in the 64-bit case no longer an option.

The question is: "Can this 'reversing magical constant' be found analytically?"

PS: I do realise that this is not a hash function in a cryptograhical sense.

degski
  • 121
  • 4

0 Answers0