fix a potential collision

This commit is contained in:
afonya2 2025-05-17 18:20:58 +02:00
parent 617608e46f
commit 2f832a2066
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC

28
IGA.ts
View file

@ -98,6 +98,17 @@ function hex2bin(hex: string): string {
}
return bin
}
function xor(a: string, b: string): string {
let out = ""
for (let i = 0; i < a.length; i++) {
if (a[i] == b[i]) {
out += "0"
} else {
out += "1"
}
}
return out
}
function checksum(input: string) {
let state: string[] = []
@ -216,18 +227,13 @@ function hash(input: string, salt: number = 0, len: number = 32, seed?: number):
dataBins[i] += fixbin(dec2bin(blocks[i][0][ii]), 16)
}
}
let hashes: string[] = []
for (let i = 0; i < dataBins.length; i++) {
let hsh = bin2hex(pBin+dataBins[i])
const crc = checksum(hsh)
hsh += bin2hex(crc)
hashes.push(hsh)
}
if (hashes.length == 1) {
return hashes[0]
} else {
return hash(hashes.join(""), salt, len, padding.seed)
while (dataBins.length > 1) {
dataBins[0] = xor(dataBins[0], dataBins[1])
dataBins.splice(1, 1)
}
const crc = checksum(dataBins[0])
const hash = bin2hex(pBin + dataBins[0] + crc)
return hash
}
function verifyHash(input: string, inHash: string, salt: number = 0, len: number = 32): verifyOut {