J = Asc(Mid(txt, nC)) ' Int(crc / 2) Then mask = &HA001Ĭrc = Int(crc / 2) And &H7FFF: crc = crc Xor mask S3 = Mid(s, 2 * l3 + 1) ' the rest of the string. ' create a 12 character hash from string sĭim s1 As String, s2 As String, s3 As String Things work better - every ASCII code at least starts out life as its own value.Ĭombining this change with the proposal I made earlier, you get the following code: Function hash12(s As String) If you replace the line with j = asc(mid(txt, nC, 1)) That anything good comes out at all is a miracle. This only handles text that can be interpreted as hex values: lowercase and uppercase letters are the same, and anything after F in the alphabet is ignored (as far as I can tell). There is a serious flaw in your original CRC16 code - namely the line that says: j = Val("&H" + Mid(txt, nC, 2)) I could write the code but based on the quality of the question I think you can take it from here!ĮDIT: It turns out that that advice is not enough. Run your "short" algorithm on each, and concatenate the results. Split your string into three shorter strings (if not divisible by three, the last one will be longer than the other two). Here is my test workbook with all example functions and a big number of test strings. 5 digits hash = 0 collisions in 6895 lines = 0 % collision rate.4 digits hash = 36 collisions in 6895 lines = 0.5 % collision rate.NET since it uses library "Microsoft MSXML" hash is a 28 characters long unicode string (case sensitive + special chars).Function: =BASE64SHA1(A1) with this Code.6 digits hash = 0 collisions in 6895 lines = 0 % collision rate.5 digits hash = 51 collisions in 6895 lines = 0.73 % collision rate.4 digits hash = 726 collisions in 6895 lines = 10.5 % collision rate.hash is a 40 characters long HEX string.Function: =SHA1TRUNC(A1) with this Code.8 digits long hash = 18 collisions in 6895 lines = 0.23 % collision rate.characters to reduce collision rate even more
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |