forked from cpu0x00/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.h
33 lines (26 loc) · 896 Bytes
/
hash.h
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
#pragma once
#include <windows.h>
#include <iostream>
#include <cstring>
DWORD getStringAsDWORD(const char* str) {
DWORD value = 0;
int len = std::strlen(str);
for (int i = 0; i < len; ++i) {
value = (value << 5) + value + str[i]; // Combine each character
}
return value;
}
DWORD WEIRDHASHA(_In_ const char* String, SIZE_T Iterations) {
SIZE_T Index = 0;
DWORD Hash = 5381; // Starting with a prime number
SIZE_T Length = Iterations;
// Compute the hash with the given number of iterations
while (Index != Length) {
Hash = (Hash << 5) + Hash; // Equivalent to Hash * 33
Index++;
}
// Obtain DWORD from the first 4 characters of the string
DWORD dwString = getStringAsDWORD(String);
// Multiply the hash by this DWORD value
return Hash * dwString + lstrlenA(String);
}