public Matrix GetBasisOfWeight(Matrix B, int weight, int num) { Matrix res = new Matrix(), Bchange, B_copy = new Matrix(B); while (res.size[0] < num) { Bchange = MatrixFuncs.GenNoise(B.size[0]); B_copy = Bchange * B_copy; for (int i = 0; i < B.size[0]; ++i) { if (Common.wt(B_copy.data[i]) == weight) { if (MatrixFuncs.Gauss(res & new Vector(B_copy.data[i])) == res.size[0] + 1) { ; } res &= new Vector(B_copy.data[i]); } if (res.size[0] == num) { break; } } } return(res); }
public Matrix R; // secret key public double KeyGen(CodeType codetype, int[] param) { Code code = new Code(); int k = 0, n = 0, r, m, l = param[2]; switch (codetype) { case CodeType.Hamming: r = param[0]; code = new Ham(r); break; case CodeType.RM: r = param[0]; m = param[1]; code = new RM(r, m); break; } k = code.G.size[0]; n = code.G.size[1]; Stopwatch t = new Stopwatch(); t.Start(); //Matrix N N = MatrixFuncs.GenNoise(k); //Matrix P int nn = n + l; P = new Matrix(nn, nn); int[] check = new int[nn]; int ind = 0; for (int i = 0; i < nn; ++i) { do { ind = Common.GetRand() % nn; } while (check[ind] == 1); P.data[ind][i] = 1; check[ind] = 1; } //Matrix R R = new Matrix(k, l); for (int i = 0; i < k; ++i) { for (int j = 0; j < l; ++j) { R.data[i][j] = Common.GetRand() & 1; } } Gp = N * (code.G | R) * P; t.Stop(); return(t.ElapsedMilliseconds / 1000.00); }
public Matrix P; // secret key public double KeyGen(CodeType codetype, int[] param) { Code code = new Code(); int k, n, r = 0, s = 0, m, nn; switch (codetype) { case CodeType.Hamming: r = param[0]; s = param[1]; code = new Ham(r); break; case CodeType.RM: r = param[0]; m = param[1]; s = param[2]; code = new RM(r, m); break; } k = code.G.size[0]; n = code.G.size[1]; nn = n * s; Stopwatch t = new Stopwatch(); t.Start(); //Matrix list N N = new List <Matrix>(); Matrix N_i, NG = new Matrix(); for (int ii = 0; ii < s; ++ii) { N_i = MatrixFuncs.GenNoise(k); N.Add(N_i); NG |= N_i * code.G; } //Matrix P P = new Matrix(nn, nn); int[] check = new int[nn]; int ind = 0; for (int i = 0; i < nn; ++i) { do { ind = Common.GetRand() % nn; } while (check[ind] == 1); P.data[ind][i] = 1; check[ind] = 1; } Gp = NG * P; t.Stop(); return(t.ElapsedMilliseconds / 1000.00); }
public Matrix P; // secret key public double KeyGen(CodeType codetype, int[] param) { Code code = new Code(); int k = 0, n = 0, r, m; switch (codetype) { case CodeType.Hamming: r = param[0]; code = new Ham(r); break; case CodeType.RM: r = param[0]; m = param[1]; code = new RM(r, m); break; } k = code.G.size[0]; n = code.G.size[1]; Stopwatch t = new Stopwatch(); t.Start(); //Matrix N N = MatrixFuncs.GenNoise(k); //Matrix P P = new Matrix(n, n); int[] check = new int[n]; int ind = 0; for (int i = 0; i < n; ++i) { do { ind = Common.GetRand() % n; } while (check[ind] == 1); P.data[ind][i] = 1; check[ind] = 1; } Gp = N * code.G * P; t.Stop(); return(t.ElapsedMilliseconds / 1000.00); }
public List <int>[] GetHamIndices(Code code, Ham ham, int r, int s, int n, int k) { int hweight = 1 << (r - 1); Matrix Bchange = MatrixFuncs.GenNoise(n * s - k), Hsub = GetBasisOfWeight(code.H, s * hweight, n - k); IEnumerable <int> hcol1, hcol2; List <int> check = Enumerable.Range(0, n * s).ToList(); List <int>[] res_idx = new List <int> [n]; for (int j = 0; j < n; ++j) { res_idx[j] = new List <int>(); hcol1 = ham.H.data.Select(x => x[j]); for (int jj = 0; jj < check.Count; ++jj) { hcol2 = Hsub.data.Select(x => x[check[jj]]); if (hcol2.SequenceEqual(hcol1)) { res_idx[j].Add(check[jj]); check.RemoveAt(jj); --jj; } if (res_idx[j].Count > s) { break; } } if (res_idx[j].Count != s) { Hsub = GetBasisOfWeight(code.H, s * hweight, n - k); res_idx = new List <int> [n]; check = Enumerable.Range(0, n * s).ToList(); j = -1; } } return(res_idx); }