/// <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); }
public void SetMatrixCell(int rowNumber, int colNumber, BigZp value) { if ((RowCount <= rowNumber) || (ColCount <= colNumber)) { throw new ArgumentException("Illegal matrix cell."); } data[rowNumber][colNumber] = value.Value; }
/// <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 BigZp[] SumMatrixRows() { var sum = new BigInteger[ColCount]; for (int i = 0; i < RowCount; i++) { for (int j = 0; j < ColCount; j++) { sum[j] += data[i][j]; } } var zpSum = new BigZp[ColCount]; for (int j = 0; j < ColCount; j++) { zpSum[j] = new BigZp(Prime, sum[j]); } return(zpSum); }
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); }
/// <summary> /// Discrete logarithm encryption. /// </summary> /// <param name="x">Value to be encrypted.</param> /// <param name="p">Prime modulus. Should be large enough (> 1024 bits) to ensure security.</param> public static BigInteger DLEncrypt(BigZp x, BigInteger p) { return(BigInteger.ModPow(2, x.Value, p)); }
/* calculate i mod prime */ private BigInteger Modulo(BigInteger i) { return(BigZp.Modulo(i, Prime)); }