/********************************************************************* * pgp_calc.cc -- This calculates and displays all other PGP related * exponents/numbers from only P, Q, (the two factors of N), and E, the * public exponent. E is normaly publicly available, and P and Q must * be found from N. * * Requires a large integer library (such as GMP) and a class named * "Integer" that supports it (+, -, *, etc.) in the file. * * Compile: * g++ -o pgp_calc pgp_calc.cc libgmp.a * Invoke: * ./pgp_calc [P] [Q] [E] * Changelog: * 971024: Created - Paul Herman ******************************************************************/ #include int main(int argc, char **argv) { Integer p, q, n, jn, d, e, u; int count, arg; count = argc - 1; // # of ints given p=0; q=0; e=0; if (count > 0 && argv[1][0] == '-') { cerr << "Usage: " << argv[0] << " [P] [Q] [E]" << endl; cerr << " P, Q -- factors of public modulus, N" << endl; cerr << " E -- public exponent" << endl; return -1; } if (count > 0) p = argv[1]; else {cout << "Enter the first factor of N (P):"; cin >> p;} if (count > 1) q = argv[2]; else {cout << "Enter the second factor of N (Q):"; cin >> q;} if (count > 2) e = argv[3]; else {cout << "Enter the public exponent (E):"; cin >> e;} n = p*q; // N = P*Q jn = (p-1) * (q-1); // J(N) = Euler Totient function d = InvModN(e, jn); // E*D = 1 (mod J(N)) if (p