Chore: a hash collision test

This commit is contained in:
SukkaW
2024-10-12 12:37:45 +08:00
parent dc221f5269
commit 66b0a3697d
4 changed files with 66 additions and 0 deletions

View File

@@ -43,4 +43,15 @@ export function fnv1a52(str: string) {
);
}
export function fnv1a(s: string) {
let h = 0x81_1C_9D_C5;
for (let i = 0, l = s.length; i < l; i++) {
h ^= s.charCodeAt(i);
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
}
return (h >>> 0);
}
export const stringHash = (payload: string) => fnv1a52(payload).toString(36) + payload.length.toString(36);