-
Notifications
You must be signed in to change notification settings - Fork 235
/
HashStringRotr32.cpp
41 lines (33 loc) · 941 Bytes
/
HashStringRotr32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Win32Helper.h"
UINT32 HashStringRotr32SubA(UINT32 Value, UINT Count)
{
DWORD Mask = (CHAR_BIT * sizeof(Value) - 1);
Count &= Mask;
#pragma warning( push )
#pragma warning( disable : 4146)
return (Value >> Count) | (Value << ((-Count) & Mask));
#pragma warning( pop )
}
INT HashStringRotr32A(_In_ LPCSTR String)
{
INT Value = 0;
for (INT Index = 0; Index < StringLengthA(String); Index++)
Value = String[Index] + HashStringRotr32SubA(Value, 7);
return Value;
}
UINT32 HashStringRotr32SubW(UINT32 Value, UINT Count)
{
DWORD Mask = (CHAR_BIT * sizeof(Value) - 1);
Count &= Mask;
#pragma warning( push )
#pragma warning( disable : 4146)
return (Value >> Count) | (Value << ((-Count) & Mask));
#pragma warning( pop )
}
INT HashStringRotr32W(_In_ LPCWSTR String)
{
INT Value = 0;
for (INT Index = 0; Index < StringLengthW(String); Index++)
Value = String[Index] + HashStringRotr32SubW(Value, 7);
return Value;
}