kevinalberts Posted August 18 Share Posted August 18 Hello everybody, i was searching some hashing ways beside most used ones like 'MD5' and some more. I found 'Joaat' way. It seems like being made with this way; Func joaat_to_lower($c) If Asc($c) >= Asc("A") And Asc($c) <= Asc("Z") Then Return Chr(Asc($c) + 32) Else Return $c EndIf EndFunc Func joaat($str) Local $hash = 0 Local $lowerChar, $char For $i = 1 To StringLen($str) $char = StringMid($str, $i, 1) $lowerChar = joaat_to_lower($char) $hash += AscW($lowerChar) $hash += BitShift($hash, -10) $hash = BitXOR($hash, BitShift($hash, 6)) Next $hash += BitShift($hash, -3) $hash = BitXOR($hash, BitShift($hash, 11)) $hash += BitShift($hash, -15) Return $hash EndFunc $sJoaat = "A" MsgBox(64, "", "name: " & $sJoaat & @CRLF & "int32: " & Joaat($sJoaat) & @CRLF & "hex: " & "0x" & Hex(Joaat($sJoaat))) Somehow it shows correct when it's like 1-2 chars (for example 'AB', 'ZX') but i still don't understand why it doesn't show correct when you try 'Example'. I also realized it's wrong if it's more than 3 characters. What am i doing wrong? (Also see: Joaat source) Link to comment Share on other sites More sharing options...
jchd Posted August 18 Share Posted August 18 This algorithm is a toy, not for use for any more or less serious application. Even the (now obsolete) MD5 is gazillions time superior. Switch to SHA3 for now. See examples by searching the forum. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
kevinalberts Posted August 19 Author Share Posted August 19 6 hours ago, jchd said: This algorithm is a toy, not for use for any more or less serious application. Even the (now obsolete) MD5 is gazillions time superior. Switch to SHA3 for now. See examples by searching the forum. I already know how to use them. But what about making this work instead? Since my question isn't about MD5 or SHA3? Link to comment Share on other sites More sharing options...
Solution jchd Posted August 19 Solution Share Posted August 19 (edited) Relax, my remark was just to warn you that this hash isn't safe, in case you wouldn't already know. Bit shifts in AutoIt are arithmetical shifts, not logical shifts. Also integers are signed. Hence you need to guard against the high bit turning on, since the interpreted value gets then negative. Not having unsigned integers datatypes is sometimes a pain, like in this case. I posted long ago machine code for all kinds of bit shifts and bit rotate but I'm currently unable to find that code. As a workaround, you can use this: expandcollapse popupLocal $t = DllStructCreate("int64 h") Local $t2 = DllStructCreate("uint lo;uint hi", DllStructGetPtr($t)) Func joaat($str) Local $char ; $str = StringLower($str) $t.h = 0 For $i = 1 To StringLen($str) $char = StringMid($str, $i, 1) $t.h += Asc($Char) $t2.hi = 0 $t.h += BitShift($t.h, -10) $t2.hi = 0 $t.h = BitXOR($t.h, BitShiftR($t, 6)) $t2.hi = 0 Next $t.h += BitShift($t.h, -3) $t2.hi = 0 $t.h = BitXOR($t.h, BitShiftR($t, 11)) $t2.hi = 0 $t.h += BitShift($t.h, -15) Return $t2.lo EndFunc Func BitShiftR($t, $n) $n = 2 ^ $n $t.h = $t.h / $n Return $t.h EndFunc Local $aTxt = ["a", "Ab", "Example", "The quick brown fox jumps over the lazy dog"] For $s In $aTxt ConsoleWrite(Hex(Joaat($s), 8) & @LF) Next It's possible that some "$t2.hi = 0" are superflous, but I've learned to be cautious with those bit games. You can check that the first and last examples match wikipedia hashes. For that to work, I've uncommented the StringLower conversion. Edited August 19 by jchd commented, not UNcommented kevinalberts 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
kevinalberts Posted August 19 Author Share Posted August 19 (edited) Thanks for help, but $aTxt[1], [2], [3] still shows wrong -- Works. Edited August 19 by kevinalberts Link to comment Share on other sites More sharing options...
jchd Posted August 19 Share Posted August 19 Works for "a" and "The quick brown fox jumps over the lazy dog", according to the wikipedia page. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
kevinalberts Posted August 19 Author Share Posted August 19 ah yes my bad, it's correct thanks a lot! 1 more question, why did we remove StringLower? Link to comment Share on other sites More sharing options...
jchd Posted August 19 Share Posted August 19 Because my only reference was those two strings and the non-lowered hash version. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now