# Jhash

```cpp
#include <Windows.h>

SIZE_T StringLengthW(_In_ LPCWSTR String)
{
	LPCWSTR String2;

	for (String2 = String; *String2; ++String2);

	return (String2 - String);
}

UINT32 RotateToLeft32(UINT32 x, UINT32 Rotate)
{
    return (x << Rotate) | (x >> (32 - Rotate));
}

UINT32 HashStringJHash32W(PWCHAR String, SIZE_T Length, UINT32 Seed)
{
    PBYTE Pointer = (PBYTE)String;
    UINT32 State0 = 0xdeadbeefU + (UINT32)Length + Seed;
    UINT32 State1 = State0;
    UINT32 State2 = State0;

    switch (Length) 
    {
        case 18: State2 += (UINT32)Pointer[17] << 8;
        case 17: State2 += (UINT32)Pointer[16];
        case 16: State1 += (UINT32)Pointer[15] << 24;
        case 15: State1 += (UINT32)Pointer[14] << 16;
        case 14: State1 += (UINT32)Pointer[13] << 8;
        case 13: State1 += (UINT32)Pointer[12];
        case 12: State0 += (UINT32)Pointer[11] << 24;
        case 11: State0 += (UINT32)Pointer[10] << 16;
        case 10: State0 += (UINT32)Pointer[9] << 8;
        case 9: State0 += (UINT32)Pointer[8];
        case 8: State1 += (UINT32)Pointer[7] << 24;
        case 7: State1 += (UINT32)Pointer[6] << 16;
        case 6: State1 += (UINT32)Pointer[5] << 8;
        case 5: State1 += (UINT32)Pointer[4];
        case 4: State0 += (UINT32)Pointer[3] << 24;
        case 3: State0 += (UINT32)Pointer[2] << 16;
        case 2: State0 += (UINT32)Pointer[1] << 8;
        case 1: State0 += (UINT32)Pointer[0];
        default: break;
    }

    State2 ^= State1; State2 -= RotateToLeft32(State1, 14);
    State0 ^= State2; State0 -= RotateToLeft32(State2, 11);
    State1 ^= State0; State1 -= RotateToLeft32(State0, 25);
    State2 ^= State1; State2 -= RotateToLeft32(State1, 16);
    State0 ^= State2; State0 -= RotateToLeft32(State2, 4);
    State1 ^= State0; State1 -= RotateToLeft32(State0, 14);
    State2 ^= State1; State2 -= RotateToLeft32(State1, 24);

    return State2;
}

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

    Hash = HashStringJHash32W(StringHashExample, (StringLengthW(StringHashExample) * sizeof(WCHAR)), 1);

    return ERROR_SUCCESS;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malwaresourcecode.com/home/string-hashing/jhash.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
