Tweak hash function and add test
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s

This commit is contained in:
themodrnhakr 2025-03-21 20:22:12 -05:00
parent 7be40debe7
commit 8d3ef2b799

View File

@ -1,3 +1,16 @@
@lazy
function test_hashInteger($test_val) {
$integerToHash = $test_val;
database.crypt.hashInteger();
tellraw @a $hashedInteger.toString();
database.crypt.clean();
tellraw @a $hashedInteger.toString();
}
class database.crypt { class database.crypt {
function hashString() {} function hashString() {}
@ -6,12 +19,19 @@ class database.crypt {
$cryptConstant = 7; $cryptConstant = 7;
$cryptPrime = 15331; $cryptPrime = 15331;
$$input = $(integer); #
$hash = $input; # $integerToHash must already be initialized
$hash *= $cryptMultiplyer; #
$hash += $cryptConstant; $hashedInteger = $integerToHash;
$hash %= $cryptPrime; $hashedInteger *= $cryptMultiplyer;
$hashedInteger += $cryptConstant;
$hashedInteger %= $cryptPrime;
tellraw @a $hash.toString(); # run database.crypt.clean() after hased value is used
}
function clean() {
scoreboard players reset $integerToHash __variable__;
scoreboard players reset $hashInteger __variable__;
} }
} }