Leaked source code of windows server 2003
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.

54 lines
1.4 KiB

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. // Note: this function is also in ..\wizard\keymake.cpp so make changes in both places
  6. void MakeKey(char * pszSeed, int fCorp)
  7. {
  8. int i;
  9. unsigned long dwKey;
  10. char szKey[5];
  11. i = strlen(pszSeed);
  12. if (i < 6)
  13. {
  14. // extend the input seed to 6 characters
  15. for (; i < 6; i++)
  16. pszSeed[i] = (char)('0' + i);
  17. }
  18. // let's calculate the DWORD key used for the last 4 chars of keycode
  19. // multiply by my first name
  20. dwKey = pszSeed[0] * 'O' + pszSeed[1] * 'L' + pszSeed[2] * 'I' +
  21. pszSeed[3] * 'V' + pszSeed[4] * 'E' + pszSeed[5] * 'R';
  22. // multiply the result by JONCE
  23. dwKey *= ('J' + 'O' + 'N' + 'C' + 'E');
  24. dwKey %= 10000;
  25. if (fCorp)
  26. {
  27. // give a separate keycode based on corp flag or not
  28. // 9 is chosen because is is a multiplier such that for any x,
  29. // (x+214) * 9 != x + 10000y
  30. // we have 8x = 10000y - 1926 which when y=1 gives us 8x = 8074
  31. // since 8074 is not divisible by 8 where guaranteed to be OK since
  32. // the number on the right can only increase by 10000 increments which
  33. // are always divisible by 8
  34. dwKey += ('L' + 'E' + 'E');
  35. dwKey *= 9;
  36. dwKey %= 10000;
  37. }
  38. sprintf(szKey, "%04d", dwKey);
  39. strcpy(&pszSeed[6], szKey);
  40. }