feat: fully functional arithmetic operations on a particular curve
curve: y ^ 2 % = (x ^ 3 + x + 10) mod p; p == 71 operations: * P + Q = R (point addition) * P + P = 2P (point doubling) * curve generation closes #1
This commit is contained in:
parent
270b8d0967
commit
0f444c1c40
13
Program.cs
13
Program.cs
|
@ -33,7 +33,7 @@ namespace KRY_0x06_cli
|
|||
v = x;
|
||||
}
|
||||
v %= nn;
|
||||
if (v < 0) v = (v + nn) % nn;
|
||||
if (v < 0) return (v + nn) % nn;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,8 @@ namespace KRY_0x06_cli
|
|||
}
|
||||
else
|
||||
{
|
||||
int slope = (Convert.ToInt32(Math.Pow(3 * P1[0],2) + a) * inverse) % 71;
|
||||
double bs = Math.Pow(P1[0], 2);
|
||||
int slope = ((3 * Convert.ToInt32(bs)+a) * inverse) % 71;
|
||||
if (slope < 0)
|
||||
{
|
||||
slope = 71 + slope;
|
||||
|
@ -75,7 +76,13 @@ namespace KRY_0x06_cli
|
|||
}
|
||||
else
|
||||
{
|
||||
int inverse = mmi( P2[0] - P1[0], 71);
|
||||
int bs = P2[0] - P1[0];
|
||||
/*
|
||||
* pre-computation needed here as later on a negative value could be passed to mmi(), which would result in incorrect further computations;
|
||||
* learnt the hard way
|
||||
*/
|
||||
if (bs < 0) bs += 71;
|
||||
int inverse = mmi( bs, 71);
|
||||
if (inverse == 0)
|
||||
{
|
||||
Console.WriteLine("You have reached infinity!");
|
||||
|
|
Loading…
Reference in New Issue