Developers.Hash.Sample.HashData.Shareaza20

From Shareaza Wiki
Jump to navigation Jump to search

HashData for Shareaza 2.0

<source lang="c"> // Test function void Test() {

// Compute the hash of nothing, and then the 5 bytes of the ASCII text "hello" HashData(NULL, 0); HashData[[byte*)"hello", 5); }

// Takes a pointer to some memory and the number of bytes of data there // Hashes the data using MD4, MD5, SHA1, TigerTree, and eDonkey2000 void HashData(byte* p, DWORD bytes) {

// Make objects that will compute the hashes CMD4 md4; CMD5 md5; CSHA sha1; CTigerTree tiger; CED2K donkey;

// For tiger and donkey, you have to call BeginFile first tiger.BeginFile(9, bytes); // Tell it the tiger height is 9, and the file size donkey.BeginFile(bytes); // Tell it the file size

// Give the objects the data we want hashed md4.Add(p, bytes); md5.Add(p, bytes); sha1.Add(p, bytes); tiger.AddToFile(p, bytes); donkey.AddToFile(p, bytes);

// Tell the objects that's all the data we have md4.Finish(); md5.Finish(); sha1.Finish(); tiger.FinishFile(); donkey.FinishFile();

// Make local variables to hold the hash values MD4 md4value; MD5 md5value; SHA1 sha1value; TIGEROOT tigervalue; MD4 donkeyvalue;

// You can call sizeof on these DWORD size; size = sizeof(md4value); // CMD4 uses a 16 byte MD4 to hold its value size = sizeof(md5value); // CMD5 uses a 16 byte MD5 to hold its value size = sizeof(sha1value); // CSHA uses a 20 byte SHA1 to hold its value size = sizeof(tigervalue); // CTigerTree uses a 24 byte TIGEROOT to hold its value size = sizeof(donkeyvalue); // CED2K uses a 16 byte MD4 to hold its value

// Have the objects write the hashes they computed into the hash value variables md4.GetHash(&md4value); md5.GetHash(&md5value); sha1.GetHash(&sha1value); tiger.GetRoot(&tigervalue); donkey.GetRoot(&donkeyvalue);

// Express the values as text using base 16 and base 32 CString md4base16 = tobase16byte*)(&md4value), sizeof(md4value; CString md5base16 = tobase16byte*)(&md5value), sizeof(md5value; CString sha1base16 = tobase16byte*)(&sha1value), sizeof(sha1value; CString tigerbase16 = tobase16byte*)(&tigervalue), sizeof(tigervalue; CString donkeybase16 = tobase16byte*)(&donkeyvalue), sizeof(donkeyvalue; } </source>

Results

<source lang="c"> HashData(NULL, 0);

md4base16 31d6cfe0d16ae931b73c59d7e0c089c0 md5base16 d41d8cd98f00b204e9800998ecf8427e sha1base16 da39a3ee5e6b4b0d3255bfef95601890afd80709 tigerbase16 000000000000000000000000000000000000000000000000 donkeybase16 00000000000000000000000000000000

HashData[[byte*)"hello", 5);

md4base16 866437cb7a794bce2b727acc0362ee27 md5base16 5d41402abc4b2a76b9719d911017c592 sha1base16 aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d tigerbase16 398ef4d84353cbe0f831a64418f3012a5419494727186eed donkeybase16 866437cb7a794bce2b727acc0362ee27 </source>