Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PointOnCurve.cs
1using System.Text;
2using System.Numerics;
3
5{
9 public struct PointOnCurve
10 {
11 private BigInteger x;
12 private BigInteger y;
13 private BigInteger z;
14 private BigInteger t;
15 private bool nonzero;
16 private bool homogeneous;
17
23 {
24 this.x = P.x;
25 this.y = P.y;
26 this.z = P.z;
27 this.t = P.t;
28 this.nonzero = P.nonzero;
29 this.homogeneous = P.homogeneous;
30 }
31
37 public PointOnCurve(BigInteger X, BigInteger Y)
38 {
39 this.x = X;
40 this.y = Y;
41 this.z = BigInteger.One;
42 this.t = BigInteger.Zero;
43 this.nonzero = !X.IsZero || !Y.IsZero;
44 this.homogeneous = false;
45 }
46
53 public PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z)
54 {
55 this.x = X;
56 this.y = Y;
57 this.z = Z;
58 this.t = BigInteger.Zero;
59 this.nonzero = !X.IsZero || !Y.IsZero;
60 this.homogeneous = true;
61 }
62
70 public PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z, BigInteger T)
71 {
72 this.x = X;
73 this.y = Y;
74 this.z = Z;
75 this.t = T;
76 this.nonzero = !X.IsZero || !Y.IsZero;
77 this.homogeneous = true;
78 }
79
83 public BigInteger X
84 {
85 get => this.x;
86 internal set => this.x = value;
87 }
88
92 public BigInteger Y
93 {
94 get => this.y;
95 internal set => this.y = value;
96 }
97
101 public BigInteger Z
102 {
103 get => this.z;
104 internal set
105 {
106 this.z = value;
107 this.homogeneous = true;
108 }
109 }
110
114 public BigInteger T
115 {
116 get => this.t;
117 internal set
118 {
119 this.t = value;
120 this.homogeneous = true;
121 }
122 }
123
127 public bool NonZero
128 {
129 get => this.nonzero;
130 internal set => this.nonzero = value;
131 }
132
136 public bool IsHomogeneous
137 {
138 get => this.homogeneous;
139 internal set => this.homogeneous = value;
140 }
141
145 public bool IsXZero => this.x.IsZero;
146
150 public bool IsYZero => this.y.IsZero;
151
153 public override string ToString()
154 {
155 StringBuilder sb = new StringBuilder();
156
157 sb.Append('(');
158 sb.Append(this.x.ToString());
159 sb.Append(',');
160 sb.Append(this.y.ToString());
161
162 if (this.homogeneous)
163 {
164 sb.Append(',');
165 sb.Append(this.z.ToString());
166 sb.Append(',');
167 sb.Append(this.t.ToString());
168 }
169
170 sb.Append(')');
171
172 return sb.ToString();
173 }
174
176 public override bool Equals(object obj)
177 {
178 return obj is PointOnCurve P &&
179 this.x.Equals(P.x) &&
180 this.y.Equals(P.y) &&
181 this.z.Equals(P.z) &&
182 this.t.Equals(P.t) &&
183 this.nonzero.Equals(P.nonzero) &&
184 this.homogeneous.Equals(P.homogeneous);
185 }
186
188 public override int GetHashCode()
189 {
190 return
191 this.x.GetHashCode() ^
192 this.y.GetHashCode() ^
193 this.z.GetHashCode() ^
194 this.t.GetHashCode() ^
195 this.nonzero.GetHashCode() ^
196 this.homogeneous.GetHashCode();
197 }
198
203 public void CopyFrom(PointOnCurve C)
204 {
205 this.x = C.x;
206 this.y = C.y;
207 this.z = C.z;
208 this.t = C.t;
209 this.nonzero = C.nonzero;
210 this.homogeneous = C.homogeneous;
211 }
212
217 public void Normalize(PrimeFieldCurve Curve)
218 {
219 if (this.homogeneous)
220 {
221 this.x = Curve.ModulusP.Divide(this.x, this.z);
222 this.y = Curve.ModulusP.Divide(this.y, this.z);
223 this.z = BigInteger.One;
224 this.t = BigInteger.Zero;
225 this.homogeneous = false;
226 }
227
228 if (this.x.Sign < 0)
229 this.x += Curve.Prime;
230
231 if (this.y.Sign < 0)
232 this.y += Curve.Prime;
233 }
234 }
235}
BigInteger Divide(BigInteger a, BigInteger b)
Divides two numbers, modulus p
Definition: ModulusP.cs:91
Base class of Elliptic curves over a prime field.
ModulusP ModulusP
Arithmetic modulus p (the prime)
Represents a point on a curve.
Definition: PointOnCurve.cs:10
void Normalize(PrimeFieldCurve Curve)
Normalizes a point, if in homogeneous coorinates.
PointOnCurve(BigInteger X, BigInteger Y)
Represents a point on a curve.
Definition: PointOnCurve.cs:37
PointOnCurve(PointOnCurve P)
Represents a point on a curve.
Definition: PointOnCurve.cs:22
bool IsYZero
If the Y-coordinate is zero.
void CopyFrom(PointOnCurve C)
Copies the value from point C .
PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z, BigInteger T)
Represents a point on a curve.
Definition: PointOnCurve.cs:70
bool IsXZero
If the X-coordinate is zero.
PointOnCurve(BigInteger X, BigInteger Y, BigInteger Z)
Represents a point on a curve.
Definition: PointOnCurve.cs:53
bool IsHomogeneous
If the point is in homogeneous coordinates.
bool NonZero
If the point is not zero (infinity).