//public static int SolveWithoutFiniteField(int[] coefficients, int x)
        //{
        //    int y = 0;

        //    for (int i = 0; i < coefficients.Length; i++)
        //    {
        //        y += coefficients[i] * Convert.ToInt32(Math.Pow(x, coefficients.Length - i - 1));
        //    }

        //    return y;
        //}

        public static uint[,] GetRandomPoints(ushort[] coefficients, int count)
        {
            var pointsArr = new uint[count, 2];
            var point     = new uint[2];

            for (int i = 0; i < count; i++)
            {
                pointsArr[i, 0] = PolynomGenerator.GetRandomX(PolynomGenerator.lowerXBound, PolynomGenerator.upperXBound);
                pointsArr[i, 1] = SolveWithFiniteField(coefficients, pointsArr[i, 0]);

                for (int j = 0; j < i; j++)
                {
                    // ensure random point
                    if (pointsArr[i, 0] == pointsArr[j, 0])
                    {
                        i--;
                    }
                }
            }

            return(pointsArr);
        }
        public static string[] SplitKey(ushort[] key, int players, int required)
        {
            int keyLengthInBits = key.Length * 16;
            int polynomsCount   = key.Length;

            var polynoms = PolynomGenerator.GeneratePolynomsMatrix(key, polynomsCount, required - 1);

            //Console.WriteLine("Generated matrix:");
            //for (int i = 0; i < polynoms.GetLength(0); i++)
            //{
            //    for (int j = 0; j < polynoms.GetLength(1); j++)
            //    {
            //        Console.Write("{0} ", polynoms[i, j]);
            //    }
            //    Console.WriteLine();
            //}

            var playerPoints         = new uint[players, polynomsCount, 2];
            var currentPolynomPoints = new uint[players, 2];
            var currentPolynom       = new ushort[required];

            for (int i = 0; i < polynomsCount; i++)
            {
                currentPolynom       = polynoms.GetRow(i);
                currentPolynomPoints = PolynomSolver.GetRandomPoints(currentPolynom, players);
                for (int j = 0; j < players; j++)
                {
                    playerPoints[j, i, 0] = currentPolynomPoints[j, 0];
                    playerPoints[j, i, 1] = currentPolynomPoints[j, 1];
                }
            }

            //for (int i = 0; i < playerPoints.GetLength(0); i++)
            //{
            //    for (int j = 0; j < playerPoints.GetLength(1); j++)
            //    {
            //        Console.Write("({0}, {1})  ", playerPoints[i, j, 0], playerPoints[i, j, 1]);
            //    }
            //    Console.WriteLine();
            //}

            var geneneratedHexes = new string[players];

            var currentPlayerPoints = new uint[polynomsCount * 2];
            var counter             = 0;

            for (int i = 0; i < playerPoints.GetLength(0); i++)
            {
                for (int j = 0; j < playerPoints.GetLength(1); j++)
                {
                    currentPlayerPoints[counter] = playerPoints[i, j, 0];
                    counter++;
                    currentPlayerPoints[counter] = playerPoints[i, j, 1];
                    counter++;
                }
                counter             = 0;
                geneneratedHexes[i] = HexConverter.NumbersArrToHexString(currentPlayerPoints, '-');
                //Console.WriteLine(geneneratedHexes[i]);
                //Console.WriteLine();
            }

            return(geneneratedHexes);
        }