Advertisement
Krythic

Seed Generation Algorithm

Jan 12th, 2016
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1.         /// <summary>
  2.         ///
  3.         /// AUTHOR: Gordon Kyle Wallace, "Krythic".
  4.         ///
  5.         /// This function is the conceptual equivalent to .NET String.GetHashCode().
  6.         /// The only difference is that this function is platform independent,
  7.         /// and is not corrupted by the faggotry of incompetent Microsoft Programmers.
  8.         /// So the value will always remain the same across different computers
  9.         /// and platforms. This will ensure that random number generation
  10.         /// will always be the same, no matter the computer the code is run on.
  11.         /// (But seriously, fuck anything but Windows)
  12.         /// </summary>
  13.         /// <param name="password"></param>
  14.         /// <returns></returns>
  15.         private static int GenerateSeed( string password )
  16.         {
  17.             char[] passwordCharacters = password.ToCharArray();
  18.             int lastCharacterIndex = passwordCharacters.Length - 1;
  19.             int first = 0x15051505;
  20.             int second = first;
  21.             int index = 0;
  22.             while( index <= lastCharacterIndex )
  23.             {
  24.                 char currentPasswordCharacter = passwordCharacters[ index ];
  25.                 char nextPasswordCharacter = ++index > lastCharacterIndex ? '\0' : passwordCharacters[ index ];
  26.                 first = ( ( ( first << 5 ) + first ) + ( first >> 0x1b ) ) ^ ( nextPasswordCharacter << 16 | currentPasswordCharacter );
  27.                 if( ++index > lastCharacterIndex ) break;
  28.                 currentPasswordCharacter = passwordCharacters[ index ];
  29.                 nextPasswordCharacter = ++index > lastCharacterIndex ? '\0' : passwordCharacters[ index++ ];
  30.                 second = ( ( ( second << 5 ) + second ) + ( second >> 0x1b ) ) ^ ( nextPasswordCharacter << 16 | currentPasswordCharacter );
  31.             }
  32.             return first + second * 0x5d588b65;
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement