From 8d3ef2b7994a62bec365bd12726359252f9914e2 Mon Sep 17 00:00:00 2001 From: themodrnhakr Date: Fri, 21 Mar 2025 20:22:12 -0500 Subject: [PATCH] Tweak hash function and add test --- src/database/crypt.jmc | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/database/crypt.jmc b/src/database/crypt.jmc index b5dd9be..66283e7 100644 --- a/src/database/crypt.jmc +++ b/src/database/crypt.jmc @@ -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 { function hashString() {} @@ -6,12 +19,19 @@ class database.crypt { $cryptConstant = 7; $cryptPrime = 15331; - $$input = $(integer); - $hash = $input; - $hash *= $cryptMultiplyer; - $hash += $cryptConstant; - $hash %= $cryptPrime; + # + # $integerToHash must already be initialized + # + $hashedInteger = $integerToHash; + $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__; } }