Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
956 B

4 years ago
  1. /*-------------------------------------------------------------------- --------*/
  2. /* HASH.C
  3. */
  4. #include "hash.h"
  5. #include <string.h>
  6. #define MAX_CHARS 43L
  7. #ifndef _WIN32
  8. #define strlen _fstrlen
  9. #endif
  10. DWORD PASCAL HashFromSz(LPCSTR szKey)
  11. {
  12. int ich, cch;
  13. DWORD hash = 0;
  14. cch = strlen(szKey);
  15. for (ich = 0; ich < cch; ++ich) {
  16. if (szKey[ich] == '!')
  17. hash = (hash * MAX_CHARS) + 11;
  18. else if (szKey[ich] == '.')
  19. hash = (hash * MAX_CHARS) + 12;
  20. else if (szKey[ich] == '_')
  21. hash = (hash * MAX_CHARS) + 13;
  22. else if (szKey[ich] == '0')
  23. hash = (hash * MAX_CHARS) + 10;
  24. else if (szKey[ich] <= 'Z')
  25. hash = (hash * MAX_CHARS) + (szKey[ich] - '0');
  26. else
  27. hash = (hash * MAX_CHARS) + (szKey[ich] - '0' - ('a' - 'A'));
  28. }
  29. /*
  30. * Since the value 0 is reserved as a nil value, if any context
  31. * string actually hashes to this value, we just move it.
  32. */
  33. return (hash == 0 ? 1 : hash);
  34. }