From 3bc7961010518e153c7c7910c9711e23e307b5ca Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:52:10 -0500 Subject: [PATCH] add cyrb128 hash function --- mods/code_library.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mods/code_library.js b/mods/code_library.js index 031942ac..7553445b 100644 --- a/mods/code_library.js +++ b/mods/code_library.js @@ -40,6 +40,24 @@ return Math.floor(Math.random() * (max - min + 1)) + min }; + //cyrb128 idk where this comes from but it was in the same thread + function cyrb128(str) { + let h1 = 1779033703, h2 = 3144134277, + h3 = 1013904242, h4 = 2773480762; + for (let i = 0, k; i < str.length; i++) { + k = str.charCodeAt(i); + h1 = h2 ^ Math.imul(h1 ^ k, 597399067); + h2 = h3 ^ Math.imul(h2 ^ k, 2869860233); + h3 = h4 ^ Math.imul(h3 ^ k, 951274213); + h4 = h1 ^ Math.imul(h4 ^ k, 2716044179); + } + h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067); + h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233); + h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213); + h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179); + return [(h1^h2^h3^h4)>>>0, (h2^h1)>>>0, (h3^h1)>>>0, (h4^h1)>>>0]; + } + function mulberry32(a) { //Mulberry32 implemented in JS from StackOverflow, https://gist.github.com/tommyettinger/46a874533244883189143505d203312c return function() { var t = a += 0x6D2B79F5;