bnnm / wwiser-utils

50 stars 15 forks source link

FNV is invertible #7

Open jbosboom opened 2 years ago

jbosboom commented 2 years ago

FNV is an invertible function. Its inverse is

uint32_t ifnv(uint32_t h, string_view s) {
    for (char c : s)
        h = (h ^ c) * 0x359c449b;
    return h;
}

Then ifnv(fnv("abcd"), "dcba") == fnv(""). You can use this to speed up fnv.exe and words.py -c 2:

bnnm commented 2 years ago

Very interesting, thanks a lot for pointing this out. I've updated fnv.exe for fast suffixes and will try to optimize other stuff later.

Seems most useful for words.py to allow bigger word lists combinations, since fnv.exe is still kind of limited by the big number of false positives it makes.