> For the complete documentation index, see [llms.txt](https://malwaresourcecode.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malwaresourcecode.com/home/string-hashing/djb2.md).

# Djb2

```cpp
#include <Windows.h>

UINT32 HashStringDjb2W(PWCHAR String)
{
    UINT32 Hash = 5381;
    UCHAR c = 0;

    while ((c = (BYTE)*String++))
        Hash = ((Hash << 5) + Hash) + c;

    return Hash;
}

INT main(VOID)
{
    WCHAR StringHashExample[] = L"Hash This String";
    UINT32 Hash = 0;

    Hash = HashStringDjb2W(StringHashExample);

    return ERROR_SUCCESS;
}
```
