Advertisement
GiamPy

wphashsalted.inc | Easy to Use Hashing Functions

Jul 8th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.17 KB | None | 0 0
  1. /*
  2.  
  3.     wphashsalted.inc
  4.     "Two easy to use functions that allow you to hash strings as fast as possible."
  5.  
  6.     Copyright 2013 Giampaolo Falqui
  7.  
  8.     Licensed under the Apache License, Version 2.0 (the "License");
  9.     you may not use this file except in compliance with the License.
  10.     You may obtain a copy of the License at
  11.  
  12.         http://www.apache.org/licenses/LICENSE-2.0
  13.  
  14.     Unless required by applicable law or agreed to in writing, software
  15.     distributed under the License is distributed on an "AS IS" BASIS,
  16.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.     See the License for the specific language governing permissions and
  18.     limitations under the License.
  19.  
  20. */
  21.  
  22. #if !defined WP_Hash
  23. native WP_Hash(buffer[], len, const str[]);
  24. #endif
  25.  
  26. // stock WhirlpoolHashUnique(string[], salt[], times)
  27. // string[] - Takes the string you would like to hash.
  28. // salt[] - Takes a unique salt that will be concatenated with the string and hashed together.
  29. // times - How many times does the function have to hash the string before returning the value.
  30. stock WhirlpoolHashUnique(string[], salt[], times)
  31. {
  32.     new stringTaken[129];
  33.    
  34.     strcat(stringTaken, string);
  35.     strcat(stringTaken, salt);
  36.    
  37.     for(new i = 0; i < times; i++)
  38.         WP_Hash(stringTaken, 129, stringTaken);
  39.     return stringTaken;
  40. }
  41.    
  42. // stock WhirlpoolHashRandom(string[], salt[], times)
  43. // string[] - Takes the string you would like to hash.
  44. // times - How many times does the function have to hash the string before returning the value.
  45. // salt[] - Reference string that contains the salt returned by randomString();
  46. // salt_length - How many characters will contain the salt.
  47. stock WhirlpoolHashRandom(string[], times, salt[], salt_length)
  48. {
  49.     new stringTaken[129];
  50.    
  51.     if(salt_length < 1)
  52.     {
  53.         strcat(stringTaken, "NULL");
  54.         return stringTaken;
  55.     }      
  56.        
  57.     randomString(salt, salt_length);
  58.     strcat(stringTaken, string);   
  59.     strcat(stringTaken, salt)
  60.    
  61.     for(new i = 0; i < times; i++)
  62.         WP_Hash(stringTaken, 129, stringTaken);
  63.     return stringTaken;
  64. }
  65.  
  66. stock randomString(strDest[], strLen = 10)
  67. {
  68.     while(strLen--)
  69.         strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement