Created
June 22, 2016 13:35
-
-
Save timruffles/ecc7805a3e844c74076a388c7c70cf72 to your computer and use it in GitHub Desktop.
empirical birthday paradox calculator - for hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hashBits = parseInt(process.env.bits || 32); | |
const hashValues = Math.pow(2, hashBits); | |
const checkPoints = Array.from({ length: 9 }, (e, i) => 1 - (i+1)/10); | |
for(var uniqueHashValuesRemaining = hashValues, p = 1; | |
p > 0.1; | |
uniqueHashValuesRemaining -= 1, p *= uniqueHashValuesRemaining/hashValues | |
) { | |
if(p < checkPoints[0]) { | |
checkPoints.shift(); | |
console.log("after", hashValues - uniqueHashValuesRemaining, "hashes, p(collision) = ", ((1 - p) * 100).toFixed(0), "%"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment