Q5 ECC With Library
Q5 ECC With Library
#include <NTL/ZZ.h>
#include <NTL/ZZ_p.h>
struct Point {
ZZ_p x, y;
bool is_infinity = false;
Point() : is_infinity(true) {}
Point(ZZ_p x, ZZ_p y) : x(x), y(y), is_infinity(false) {}
};
ZZ_p m;
if (P.x == Q.x && P.y == Q.y) {
m = (3 * sqr(P.x) + a) / (2 * P.y);
} else {
m = (Q.y - P.y) / (Q.x - P.x);
}
while (n > 0) {
if (n % 2 == 1) {
result = point_add(result, current, a);
}
current = point_add(current, current, a);
n /= 2;
}
return result;
}
int main() {
// Initialize finite field
ZZ p;
conv(p, PRIME_P);
ZZ_p::init(p);
// Base point G
ZZ_p gx, gy;
conv(gx, GX);
conv(gy, GY);
Point G(gx, gy);
// Output results
cout << "Private Key: " << private_key << endl;
cout << "Public Key: (" << public_key.x << ", " << public_key.y
<< ")" << endl;
return 0;
}