コード例 #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);
        }
コード例 #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));
        }
コード例 #3
0
ファイル: FiniteFieldPoint.cs プロジェクト: imcoddy/AntShares
        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;
            }
        }
コード例 #4
0
        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);
            }
        }