do collision tests
This commit is contained in:
parent
92b96c8204
commit
8e832eb380
4 changed files with 173 additions and 2 deletions
76
collision_test2.ts
Normal file
76
collision_test2.ts
Normal file
|
@ -0,0 +1,76 @@
|
|||
import IGA from "./IGA"
|
||||
import fs from "fs"
|
||||
|
||||
type Collision = {
|
||||
hash: string
|
||||
old: string
|
||||
new: string
|
||||
randomPadding: boolean
|
||||
}
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
const len = 64
|
||||
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
let seen = {}
|
||||
let rawSeen = {}
|
||||
let collisions: Collision[] = []
|
||||
let counter = 0
|
||||
let failCount = 0
|
||||
const startTime = Date.now()
|
||||
|
||||
async function main() {
|
||||
while (true) {
|
||||
let str = ""
|
||||
for (let i = 0; i < len; i++) {
|
||||
str += alphabet[Math.floor(Math.random() * (alphabet.length - 1))]
|
||||
}
|
||||
let h = ""
|
||||
if (rawSeen[str] == undefined) {
|
||||
failCount = 0
|
||||
let hash1 = IGA.hash(str)
|
||||
h = hash1
|
||||
let hash2 = IGA.hash(str, 0, 32, 32, 32768)
|
||||
if (seen[hash1] != undefined) {
|
||||
collisions.push({
|
||||
hash: hash1,
|
||||
old: seen[hash1],
|
||||
new: str,
|
||||
randomPadding: true
|
||||
})
|
||||
} else {
|
||||
seen[hash1] = str
|
||||
}
|
||||
if (seen[hash2] != undefined) {
|
||||
if (!hash1.startsWith("8000")) {
|
||||
collisions.push({
|
||||
hash: hash2,
|
||||
old: seen[hash2],
|
||||
new: str,
|
||||
randomPadding: false
|
||||
})
|
||||
}
|
||||
} else {
|
||||
seen[hash2] = str
|
||||
}
|
||||
rawSeen[str] = true
|
||||
} else {
|
||||
failCount++
|
||||
if (failCount > 1000) {
|
||||
console.log("Finding a qunique string took too long, exiting...")
|
||||
process.exit(0)
|
||||
}
|
||||
}
|
||||
if (counter % 1000 == 0) {
|
||||
let timeTook = Math.floor((Date.now() - startTime) / 100) / 10
|
||||
console.log(`Last string: ${str}, Last hash: ${h}, Collisions: ${collisions.length}, Time: ${timeTook}s`)
|
||||
await sleep(1)
|
||||
}
|
||||
if (counter % 10000 == 0) {
|
||||
fs.writeFileSync("collisions.json", JSON.stringify(collisions))
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue