Lightweight 8 byte hash function algorithm

后端 未结 4 2261
旧巷少年郎
旧巷少年郎 2021-01-02 13:27

I need to extract an 8 byte digest from a variable length string so I\'m looking for such an algorithm that I will implement in c/c++. That will be part of a digital signatu

4条回答
  •  长发绾君心
    2021-01-02 14:04

    Here is a modified version of a 32 bit version I found in my old source files

    static unsigned long long llhash(const char *str)
    {
        unsigned long long hash = 5381;
        int c;
    
        while (c = *str++)
            hash = ((hash << 5) + hash) + c;
    
        return hash;
    }
    

    But hashing will always result in collisions. Of course some algorithms are better than others.

    Edit: I found the source of the 32 bit version: http://www.cse.yorku.ca/~oz/hash.html

提交回复
热议问题