Function cyrb53a (c) 2023 bryc (github.com/bryc) to calculate 53-bit hash from string
https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
:local cyrb53a do={
:local h1 (0xdeadbeef ^ [:tonum $2])
:local h2 (0x41c6ce57 ^ [:tonum $2])
:local imul do={
:local ah (([:tonum $1] >> 16) & 0xffff)
:local al ([:tonum $1] & 0xffff)
:local bh (([:tonum $2] >> 16) & 0xffff)
:local bl ([:tonum $2] & 0xffff)
:return (($al * $bl + (($ah * $bl + $al * $bh) << 16)) & 0xffffffff)
}
:for i from=0 to=([:len $1] - 1) step=1 do={
:local ch [:tonum "0x$[:convert [:pick $1 $i] to=hex]"]
:set h1 [$imul ($h1 ^ $ch) 0x85ebca77]
:set h2 [$imul ($h2 ^ $ch) 0xc2b2ae3d]
}
:set h1 ($h1 ^ [$imul ($h1 ^ ($h2 >> 15)) 0x735a2d97])
:set h2 ($h2 ^ [$imul ($h2 ^ ($h1 >> 15)) 0xcaf649a9])
:set h1 ($h1 ^ ($h2 >> 16))
:set h2 ($h2 ^ ($h1 >> 16))
:return (2097152 * $h2 + ($h1 >> 11))
}
:put [$cyrb53a "We like MikroTik RouterOS script writing" 0]
64-bit simplified version
:local cyrb53a do={
:local h1 (0xdeadbeef ^ [:tonum $2])
:local h2 (0x41c6ce57 ^ [:tonum $2])
:for i from=0 to=([:len $1] - 1) step=1 do={
:local ch [:tonum "0x$[:convert [:pick $1 $i] to=hex]"]
:set h1 (($h1 ^ $ch) * 0x85ebca77)
:set h2 (($h2 ^ $ch) * 0xc2b2ae3d)
}
:set h1 ($h1 ^ (($h1 ^ ($h2 >> 15)) * 0x735a2d97))
:set h2 ($h2 ^ (($h2 ^ ($h1 >> 15)) * 0xcaf649a9))
:set h1 ($h1 ^ ($h2 >> 16))
:set h2 ($h2 ^ ($h1 >> 16))
:return ((2097152 * $h2 + ($h1 >> 11)) & 0xffffffffffffffff)
}
:put [$cyrb53a "We like MikroTik RouterOS script writing" 0]
Sometimes they ask about hashes, maybe it will be useful for someone. I use it in my projects to organize quick searches in big data to calculate the keys of associative arrays, to do this, first convert the number to hex string.