I'm trying to code the Adler-32 Hash Function from scratch just to have some fun, I've gotten it completed except for the fact that every time I hash a string it's always missing the zero in the front. I've gone through the formula and Adler-32 descriptions dozens of times and I can't figure out why my code is producing it. Code Below.
function toAdler32(str) {
if (typeof str != "string") throw new Error('HashUtil: Data passed to Hash function was not of type String.');
let A16 = 1;
let B16 = 0;
for (let i = 0; i < str.length; i++) {
A16 += (str.charCodeAt(i)) % 65521;
B16 += A16 % 65521;
}
return ((B16 << 16) | A16).toString(16);
}
console.log(toAdler32('test'));
// Returns `45d01c1` when it should return `045d01c1`.