Skip to content

Instantly share code, notes, and snippets.

@jmcveigh
Created December 5, 2014 15:05
Show Gist options
  • Save jmcveigh/c240c0688a160a772363 to your computer and use it in GitHub Desktop.
Save jmcveigh/c240c0688a160a772363 to your computer and use it in GitHub Desktop.
The Birthday Attack (Approximation)
#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