/// <summary> /// Returns a Vandermonde matrix in the field (each element is modulu prime). /// </summary> public static BigZpMatrix GetShamirRecombineMatrix(int matrixSize, BigInteger prime) { var A = new BigZpMatrix(matrixSize, matrixSize, prime); if (matrixSize == 1) { A.data[0][0] = 1; return(A); } for (int i = 0; i < matrixSize; i++) { A.data[i][0] = 1; } for (int i = 0; i < matrixSize; i++) { A.data[i][1] = i + 1; } for (int i = 0; i < matrixSize; i++) { for (int j = 2; j < matrixSize; j++) { A.data[i][j] = BigZp.Modulo(A.data[i][j - 1] * A.data[i][1], prime); } } return(A); }
public static BigZpMatrix GetVandermondeMatrix(int rowNum, int colNum, BigInteger prime) { var A = new BigZpMatrix(rowNum, colNum, prime); for (int j = 0; j < colNum; j++) { A.data[0][j] = 1; } if (rowNum == 1) { return(A); } for (int j = 0; j < colNum; j++) { A.data[1][j] = j + 1; } for (int j = 0; j < colNum; j++) { for (int i = 2; i < rowNum; i++) { A.data[i][j] = BigZp.Modulo(A.data[i - 1][j] * A.data[1][j], prime); } } return(A); }
/// <summary> /// Creates and return a random rowNum-by-colNum matrix with values between '0' and 'prime-1'. /// </summary> public static BigZpMatrix GetRandomMatrix(int rowNum, int colNum, BigInteger prime) { var A = new BigZpMatrix(rowNum, colNum, prime); for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { A.data[i][j] = BigZp.Modulo(StaticRandom.Next(prime), prime); } } return(A); }
public static BigZpMatrix GetVandermondeMatrix(int rowNum, IList <BigZp> values, BigInteger prime) { int colNum = values.Count; var A = new BigZpMatrix(rowNum, colNum, prime); for (int j = 0; j < colNum; j++) { A.data[0][j] = 1; } if (rowNum == 1) { return(A); } for (int j = 0; j < colNum; j++) { for (int i = 1; i < rowNum; i++) { A.data[i][j] = BigZp.Modulo(A.data[i - 1][j] * values[j].Value, prime); } } return(A); }
/* calculate i mod prime */ private BigInteger Modulo(BigInteger i) { return(BigZp.Modulo(i, Prime)); }