示例#1
0
void
HashCreatorTester::Test()
{
    // Run basic test.
    HashCreator hasher(HashCreator::SHA256);
    AnsiString result = hasher.GenerateHash("The quick brown fox jumps over the lazy dog", "");

    if (!hasher.ValidateHash("The quick brown fox jumps over the lazy dog", result, true))
        throw 0;

    // Check that same password hashed twice yealds separate hashes.
    AnsiString test1 = hasher.GenerateHash("The quick brown fox jumps over the lazy dog", "");
    AnsiString test2 = hasher.GenerateHash("The quick brown fox jumps over the lazy dog", "");
    if (test1 == test2)
        throw 0;

    for (int i = 0; i < 250; i++)
    {
        HashCreator memoryTester(HashCreator::SHA256);

        String temp;
        temp.Format(_T("%d"), i);
        AnsiString hashableString = temp;

        hasher.GenerateHash(hashableString, "test");
    }
}
// Main to test this algorithm
int main() {
  // Setup timevals
  struct timeval startTime, endTime;
  // Run a variety of functions
  __initialize(); // Initialize the page fault simulator
  printf("=-=-=-=-= MEMORY MAXER\n\n");
  gettimeofday(&startTime, NULL); // Measure time performance
  memoryMaxer();
  gettimeofday(&endTime, NULL); // Measure time performace
  printf("=-=-=-=-= Memory Maxer Statistics:\n");
  printf(" Time taken for execution with random algorithm for picking pages = %ld msec\n\n", timedifference(endTime, startTime));
  printf("=-=-=-=-= PERSONAL FUNCTION 1\n\n");
  gettimeofday(&startTime, NULL); // Measure time performance
  memoryTester(); 
  gettimeofday(&endTime, NULL); // Measure time performace
  printf("=-=-=-=-= Personal Function 1 Statistics:\n");
  printf(" Time taken for execution with random algorithm for picking pages = %ld msec\n\n", timedifference(endTime, startTime));
  return 0;
}