// JhashD Version 1.4 Revision II #ifndef HASH_H #define HASH_H #include #include #include #include using namespace std; string hash(string &); string CharHash(char, int); const int NUM_PADS_ONE = 3; // increase or decrease the padding before the // first character const int NUM_PADS_TWO = 5; // increase or decrease the padding of letters // after the encrypted character string hash(string& password) { string TempStr; int PassLen = password.length(); int asciiCount = 0; string* HashArray; HashArray = new string[password.length()]; // create an array to hold // each hashed character for (int index = 0; index < password.length(); index++) password[index] = toupper(password[index]); // make each non-uppercase // letter uppercase for (int index = 0; index < password.length(); index++) // total up // all the ascii // variables if (password[index] != ' ') asciiCount += int(password[index]); srand(asciiCount); // Generates a new series of random numbers based on // the total value of ascii characters in the password for (int index = 0; index < password.length(); index++) HashArray[index] = CharHash(password[index], PassLen); // dump each hash character into the pointer array for (int index = 0; index < password.length(); index++) TempStr += HashArray[index]; // copy the hashes to the string delete [] HashArray; // de-allocate the memory return TempStr; } string CharHash(char charact, int size) { if (charact != ' ') { string Hash; // a variable to hold the hashes of the current character char ChRand = 65 + rand() % 26; // random letter between A to Z int NumTimes = 20 + rand() % (int(charact) + size); // manipulate the random // letter based on the ascii // value of the current // character plus the // length of the password int CharRand = 1 + rand() % (int(charact) + size); // Manipulate the character // itself based on a random // number decided by the // ascii value of the // character plus the // length of the password for (int index = 0; index < CharRand; index++) { if (charact == 'Z') { charact = 'A'; continue; } if (charact == 'z') { charact = 'a'; continue; } if (charact == '9') { charact = '0'; continue; } charact++; } for (int index = 0; index < NUM_PADS_ONE; index++) { for (int index2 = 0; index2 < NumTimes; index2++) { if (ChRand == 'Z') { ChRand = 'A'; continue; } if (ChRand == '9') { ChRand = '0'; continue; } ChRand++; } Hash += ChRand; ChRand = 65 + rand() % 26; NumTimes = 20 + rand() % (int(charact) + size); } Hash += charact; for (int index = 0; index < NUM_PADS_TWO; index++) { for (int index2 = 0; index2 < NumTimes; index2++) { if (ChRand == 'Z') { ChRand = 'A'; continue; } if (ChRand == '9') { ChRand = '0'; continue; } ChRand++; } Hash += ChRand; ChRand = 65 + rand() % 26; NumTimes = 20 + rand() % (int(charact) + size); } return Hash; } else return "........."; } #endif