fix a potential collision
This commit is contained in:
parent
617608e46f
commit
2f832a2066
1 changed files with 17 additions and 11 deletions
28
IGA.ts
28
IGA.ts
|
@ -98,6 +98,17 @@ function hex2bin(hex: string): string {
|
||||||
}
|
}
|
||||||
return bin
|
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) {
|
function checksum(input: string) {
|
||||||
let state: 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)
|
dataBins[i] += fixbin(dec2bin(blocks[i][0][ii]), 16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hashes: string[] = []
|
while (dataBins.length > 1) {
|
||||||
for (let i = 0; i < dataBins.length; i++) {
|
dataBins[0] = xor(dataBins[0], dataBins[1])
|
||||||
let hsh = bin2hex(pBin+dataBins[i])
|
dataBins.splice(1, 1)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
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 {
|
function verifyHash(input: string, inHash: string, salt: number = 0, len: number = 32): verifyOut {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue