Jump to content

Joaat Hash


Go to solution Solved by jchd,

Recommended Posts

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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

  • Solution
Posted (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:

Local $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 by jchd
commented, not UNcommented

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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...