Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        internal static bool TryParse(Match match, out FiniteFieldPoint result)
        {
            if (!match.Success)
            {
                result = null;
                return(false);
            }

            try {
                var xString = match.Groups["x"].Value.ToLowerInvariant();
                var yString = match.Groups["y"].Value.ToLowerInvariant();

                // get rid of any initial 0's
                while (xString.StartsWith("0", StringComparison.Ordinal))
                {
                    xString = xString.Substring(1);
                }

                // 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 (Exception exception) {
                result = null;
                return(false);
            }
        }
Ejemplo n.º 4
0
        internal static bool TryParse(Match match, out FiniteFieldPoint result) {
            if (!match.Success) {
                result = null;
                return false;
            }

            try {
                var xString = match.Groups["x"].Value.ToLowerInvariant();
                var yString = match.Groups["y"].Value.ToLowerInvariant();

                // get rid of any initial 0's
                while (xString.StartsWith("0", StringComparison.Ordinal)) {
                    xString = xString.Substring(1);
                }

                // 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(Exception exception) {
                result = null;
                return false;
            }
        }
Ejemplo n.º 5
0
 public SecretShare(SecretShareType shareType, FiniteFieldPoint point, string checksum = null) {
     ShareType = shareType;
     Point = point;
     Checksum = checksum;
 }
Ejemplo n.º 6
0
 public static bool TryParse(string s, out FiniteFieldPoint result) {
     var match = Regex.Match(s, RegexPattern);
     return TryParse(match, out result);
 }
Ejemplo n.º 7
0
        public static bool TryParse(string s, out FiniteFieldPoint result)
        {
            var match = Regex.Match(s, RegexPattern);

            return(TryParse(match, out result));
        }