public static string GetHexKey(ushort[] key) { var newKey = new uint[key.Length]; for (int i = 0; i < key.Length; i++) { newKey[i] = key[i]; } return(HexConverter.NumbersArrToHexString(newKey, '-')); }
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); }