Example #1
0
Hash Hasher::getResult()
{
   Hash result;
   result.newData();
   memcpy(result.data->hash, this->cryptographicHash.result().constData(), Hash::HASH_SIZE);
   return result;
}
Example #2
0
/**
  * Return a new rand hash.
  */
Hash Hash::rand()
{
   Hash hash;
   hash.newData();
   for (int i = 0; i < HASH_SIZE; i++)
      hash.data->hash[i] = static_cast<char>(Hash::mtrand.randInt(255));
   return hash;
}
Example #3
0
Hash Hash::rand(quint32 seed)
{
   MTRand mtrand(seed);
   Hash hash;
   hash.newData();
   for (int i = 0; i < HASH_SIZE; i++)
      hash.data->hash[i] = static_cast<char>(mtrand.randInt(255));
   return hash;
}
Example #4
0
Hash Hash::fromStr(const QString& str)
{
   Q_ASSERT_X(str.size() == 2 * HASH_SIZE, "Hash::fromStr", "The string representation of an hash must have twice as character as the size (in byte) of the hash.");

   Hash hash;
   hash.newData();
   const QString strLower = str.toLower();

   for (int i = 0; i < HASH_SIZE && 2*i + 1 < strLower.size(); i++)
   {
      char c1 = strLower[2*i].toAscii();
      char c2 = strLower[2*i + 1].toAscii();

      char p1 = c1 <= '9' ? c1 - '0' : c1 - 'a' + 10;
      char p2 = c2 <= '9' ? c2 - '0' : c2 - 'a' + 10;

      hash.data->hash[i] = (p1 << 4 & 0xF0) | (p2 & 0x0F);
   }

   return hash;
}