private static FiniteFieldPoint AdjustPoint(int totalPoints, FiniteFieldPoint point) { var correction = new FiniteFieldPolynomial(point.Y.PrimePolynomial, BigInteger.One); var correctionMultiplier = point.X; for (int i = 1; i <= totalPoints; i++) { correction = correction * correctionMultiplier; } var newY = point.Y + correction; return new FiniteFieldPoint(point.X, newY); }
private static FiniteFieldPoint AdjustPoint(int totalPoints, FiniteFieldPoint point) { var correction = new FiniteFieldPolynomial(point.Y.PrimePolynomial, BigInteger.One); var correctionMultiplier = point.X; for (int i = 1; i <= totalPoints; i++) { correction = correction * correctionMultiplier; } var newY = point.Y + correction; return(new FiniteFieldPoint(point.X, newY)); }
public static bool TryParse(string s, out FiniteFieldPoint result) { var match = Regex.Match(s, @"(?<x>[0-9]+)-(?<y>[0-9a-fA-F]+)"); if (!match.Success) { result = null; return false; } try { var xString = match.Groups["x"].Value.ToLowerInvariant(); var yString = match.Groups["y"].Value.ToLowerInvariant(); // Each hex letter makes up 4 bits, so to get the degree in bits // we multiply by 4 int polynomialDegree = yString.Length * 4; var irp = new IrreduciblePolynomial(polynomialDegree); var x = new FiniteFieldPolynomial(irp, BigInteger.Parse(xString)); // get bytes var bigEndianBytes = new byte[yString.Length / 2]; for (int i = 0; i < yString.Length; i += 2) { bigEndianBytes[i / 2] = Byte.Parse(yString.Substring(i, 2), NumberStyles.HexNumber); } var y = new FiniteFieldPolynomial(irp, bigEndianBytes.ToBigIntegerFromBigEndianUnsignedBytes()); result = new FiniteFieldPoint(x, y); return true; } catch { result = null; return false; } }
public static bool TryParse(string s, out FiniteFieldPoint result) { var match = Regex.Match(s, @"(?<x>[0-9]+)-(?<y>[0-9a-fA-F]+)"); if (!match.Success) { result = null; return(false); } try { var xString = match.Groups["x"].Value.ToLowerInvariant(); var yString = match.Groups["y"].Value.ToLowerInvariant(); // Each hex letter makes up 4 bits, so to get the degree in bits // we multiply by 4 int polynomialDegree = yString.Length * 4; var irp = new IrreduciblePolynomial(polynomialDegree); var x = new FiniteFieldPolynomial(irp, BigInteger.Parse(xString)); // get bytes var bigEndianBytes = new byte[yString.Length / 2]; for (int i = 0; i < yString.Length; i += 2) { bigEndianBytes[i / 2] = Byte.Parse(yString.Substring(i, 2), NumberStyles.HexNumber); } var y = new FiniteFieldPolynomial(irp, bigEndianBytes.ToBigIntegerFromBigEndianUnsignedBytes()); result = new FiniteFieldPoint(x, y); return(true); } catch { result = null; return(false); } }