[dba-VB] SHA1 to compute a hash

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Sat Mar 19 08:21:26 CDT 2011


 Hi All --

Sorry I have mentioned 6 millions cycles but my sample was for just 5
millions, and  I have got some collisions for 8 bytes long surrogate keys.
Here I'm posting a patch for hashing part of the code - and no collisions
now for 8 bytes long hashes for 5 millions cycles.

....
UInt64 longHashResult = 0xFFFFFFFFFFFFFFFF;
UInt64 longHash = 0xFFFFFFFFFFFFFFFF;
int shiftCounter = 0;
foreach (byte b in hashValue)
{
    longHash ^= b;
    longHash = longHash << 8 + 0xFF;
    if (++shiftCounter == 8)
    {
        longHashResult ^= longHash;
        shiftCounter = 0;
    }
}
longHash = longHashResult; 
...

Started at: 19/03/2011 16:08:53
19/03/2011 16:09:04: i=1000000, cs=0, cu=0
19/03/2011 16:09:17: i=2000000, cs=0, cu=0
19/03/2011 16:09:33: i=3000000, cs=0, cu=0
19/03/2011 16:09:49: i=4000000, cs=0, cu=0
19/03/2011 16:10:06: i=5000000, cs=0, cu=0

TOTALS:
Min String Length = 7
Max String Length = 25
Avg String Length = 15.4966972
Test cases Qty = 5000000
Collisions Qty = 0
ulong Collisions Qty = 0
Finished at: 19/03/2011 16:10:06

Please correct me if I've got wrong somewhere.

Thank you.

--
Shamil
 
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: 19 ????? 2011 ?. 16:04
To: stuart at lexacorp.com.pg; 'Discussion concerning Visual Basic and related
programming issues.'
Subject: Re: [dba-VB] SHA1 to compute a hash

Hi Stuart and John,

<<<
AFAIK, no one other than you has found any
>>>
Yes, I was also confused how it comes to get SHA1 hashes collisions but then
I have thought that John probably "compacts" SHA1 hashes into 8 bytes
surrogate keys?

Here (P.S.) is a "quick&dirty" "brute force" test code - 4 collisions for 6
millions cycles for 8 bytes keys.

Please correct me if you find some errors in my sample code

Thank you.

--
Shamil
 
<<< snip >>>




More information about the dba-VB mailing list