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:
surtur 2020-09-05 23:06:36 +02:00
parent 270b8d0967
commit 0f444c1c40
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 10 additions and 5 deletions

View File

@ -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!");

View File

@ -1,5 +1,3 @@
# KRY-0x06-cli
this repo holds *sawce* for cli version of `KRY-0x06`
> **Note:** WIP