Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/19/2024 in all areas

  1. jchd

    Joaat Hash

    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.
    1 point
×
×
  • Create New...