public BigIntMatrix getAndProcessRequest(BigIntMatrix[] Ms, int l0, int N, BigInteger p) { txtLog.AppendText("---------------------------- Server Started query process --------------------------"); Stopwatch sw = new Stopwatch(); sw.Start(); BigInteger[,] splittedList = spliteDB(l0, ll, N); /******* show splited list ****** * for (long i = 0; i < splittedList.GetLength(0); i++) * { * txtLog.AppendText(">>>>>>>>>> Splited Item({0})...", i); * for (long j = 0; j < splittedList.GetLength(1); j++) * { * txtLog.AppendText("> Splited({0}): {1}", j, splittedList[i,j]); * } * } * /*****************************/ BigIntMatrix Mat = CreateUserQuery(Ms, splittedList, N, n, p); BigIntMatrix V = new BigIntMatrix(1, 2 * N, 0); long len = splittedList.GetLength(0) * splittedList.GetLength(1); for (int i = 0; i < len; i++) { for (int j = 0; j < 2 * N; j++) { V.SumElement(0, j, Mat.GetElement(i, j)); } } sw.Stop(); Protocol2Time = sw.ElapsedMilliseconds; //txtLog.AppendText(">>>>>>>>>> Matrix Mat: {0}", Mat.ToString()); txtLog.AppendText(V.Modulus(p).Print("Matrix V")); txtLog.AppendText("---------------------------- Server Finished query process --------------------------"); return(V.Modulus(p)); }
private void btnSendRequest_Click(object sender, EventArgs e) { BigIntMatrix V = frmParent.getAndProcessRequest(Ms, l0, N, p); //MessageBox.Show("Your request has been sent to the server...", "request is on going", MessageBoxButtons.OK, MessageBoxIcon.Information); txtLog.AppendText("\r\n---------------------------- Server Respond to the query ------------------------------------"); txtLog.AppendText(V.Print("Result Vector from server")); //--- DePermute V --- Stopwatch sw = new Stopwatch(); sw.Start(); BigIntMatrix VPrime = Depermute(V, dePermutList, N); BigIntMatrix undisturbedHalf = VPrime.GetSubMatrix(0, 1, 0, N); //BigIntMatrix invA = A.ModInverse(p); //***---- BigIntMatrix invA = A.GaussJordanModInverse(p); BigIntMatrix resultHalf = undisturbedHalf * invA * B % p; BigIntMatrix undisturbedVector = undisturbedHalf.Append(resultHalf, BigIntMatrix.AppendMode.Beside); BigIntMatrix ScrambledNoise = (VPrime - undisturbedVector) % p; //BigIntMatrix invDelta = Delta.ModInverse(p); //***---- invDelta = Delta.GaussJordanModInverse(p); BigIntMatrix halfScrambledNoise = ScrambledNoise.GetSubMatrix(0, 1, N, N); BigIntMatrix unScrambledNoise = halfScrambledNoise * invDelta % p; //BigInteger[] eea = MyClass.Extended_GCD(q, p); //---BigInteger qInv = MathClass.NumberModInverse(q, p); BigInteger qInv = MathClass.EEA(q, p); //long qInv = (long)eea[1]; BigInteger[,] eJegon = new BigInteger[1, N]; for (int i = 0; i < N; i++) { BigInteger epsilon = MathClass.mod(unScrambledNoise.GetElement(0, i), q); if (epsilon >= q / 2) { epsilon -= q; } eJegon[0, i] = MathClass.mod(unScrambledNoise.GetElement(0, i) - epsilon, p); eJegon[0, i] *= qInv;// % p;//MyClass.mod((long)eJegon[0, i] * qInv, p); } //Matrix<double> ResultVector = Matrix<double>.Build.DenseOfArray(eJegon).Multiply(qInv).Modulus(p); BigIntMatrix ResultVector = new BigIntMatrix(eJegon).Modulus(p); BigInteger[] resVect = new BigInteger[N]; for (int i = 0; i < N; i++) { resVect[i] = ResultVector.GetElement(0, i); } BigInteger result = 0; for (int i = 0; i < N; i++) { result <<= l0; result += resVect[i]; } sw.Stop(); Protocol3Time = sw.ElapsedMilliseconds; txtLog.AppendText(ResultVector.Print("Obtained Result Vector")); txtLog.AppendText(invA.Print("Inv A")); txtLog.AppendText(invDelta.Print("Inv Delta")); txtLog.AppendText("\r\n>>>>>>>>>> Inv q = " + qInv.ToString()); txtLog.AppendText("\r\n>>>>>>>>>> Obtained Result for index(" + i0.ToString() + "): " + result.ToString()); txtLog.AppendText("\r\n--------------------------------------------- Timing ----------------------------------------------------"); long totalDuration = Protocol1Time + Protocol3Time + frmParent.Protocol2Time; txtLog.AppendText("\r\n>>> Protocol 1 Duration: " + Protocol1Time.ToString()); txtLog.AppendText("\r\n>>> Protocol 2 Duration: " + frmParent.Protocol2Time.ToString()); txtLog.AppendText("\r\n>>> Protocol 3 Duration: " + Protocol3Time.ToString()); txtLog.AppendText("\r\n>>> Total Duration: " + totalDuration.ToString()); txtLog.AppendText("\r\n>>> Matrix Process Duration: " + MatrixProcessTime.ToString()); txtLog.AppendText("\r\n>>> Deference check: " + (frmParent.getValueByIndex(i0) - result).ToString()); txtLog.AppendText("\r\n--------------------------------------------- Timing ----------------------------------------------------"); txtResult.Text = result.ToString(); txtReturnTime.Text = totalDuration.ToString(); MessageBox.Show("Query process has been finished successfully...", "Query Operation", MessageBoxButtons.OK, MessageBoxIcon.Information); }