-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_lines.cpp
More file actions
53 lines (44 loc) · 1.06 KB
/
calc_lines.cpp
File metadata and controls
53 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <string>
#include <unordered_map>
#include "modular_arithmetic.hpp"
#include "elliptic_curve.hpp"
#include "poly_and_ratio.hpp"
#include "calc_lines.hpp"
using std::string;
using std::unordered_map;
Poly calc_line(Point& P, Point& Q, EllipticCurve& E)
{
unordered_map<string, Galois> data;
if (P.isinfty() && Q.isinfty())
{
data["0, 0"] = Galois(1, E.get_mod());
}
else if (Q.get_x() != P.get_x())
{
data["0, 0"] = Q.get_x() * P.get_y() - P.get_x() * Q.get_y();
data["1, 0"] = Q.get_y() - P.get_y();
data["0, 1"] = P.get_x() - Q.get_x();
}
else
{
data["0, 0"] = -P.get_x();
data["1, 0"] = Galois(1, E.get_mod());
}
return Poly(data, E.get_mod());
}
Poly calc_tangent(Point& P, EllipticCurve& E)
{
unordered_map<string, Galois> data;
if (P.get_y() == 0)
{
data["0, 0"] = -P.get_x();
data["1, 0"] = Galois(1, E.get_mod());
}
else
{
data["0, 0"] = -P.get_y().pow(2) + (E.get_a() * P.get_x() * 2) + (E.get_b() * 3);
data["0, 1"] = -P.get_y() * 2;
data["1, 0"] = (P.get_x().pow(2) * 3) + E.get_a();
}
return Poly(data, E.get_mod());
}