Created
December 5, 2014 15:05
-
-
Save jmcveigh/c240c0688a160a772363 to your computer and use it in GitHub Desktop.
The Birthday Attack (Approximation)
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
#include <cmath> | |
#include <cstdlib> | |
#include <iostream> | |
int main(int argc, char ** argv) { | |
if (argc != 3) { | |
std::cerr << "Usage: " << argv[0] << " probability-exponent bits" << std::endl; | |
return 1; | |
} | |
long probabilityExponent = strtol(argv[1], NULL, 10); | |
double probability = pow(10, probabilityExponent); | |
long bits = strtol(argv[2], NULL, 10); | |
double outputs = pow(2, bits); | |
std::cout << sqrt(2.0 * outputs * -log1p(-probability)) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment