public MainForm() { McE = new McElice(); Sid = new Sidel_mod(); Wish = new Wish_mod(); InitializeComponent(); //Ham ham = new Ham(3); //Sid.KeyGen(CodeType.Hamming, new[] { 3, 2 }); //this.txtbox_keys.Text = "r = 3, s = 2 \r\n\r\n Original: \r\n" + Code.DualMatrix(ham.G | ham.G).ToString(); //this.txtbox_keys.Text += "\r\n Noised: \r\n" + Code.DualMatrix(Sid.N[0] * ham.G | Sid.N[1] * ham.G).ToString(); //this.txtbox_keys.Text += "\r\n Noised and permuted: \r\n" + Code.DualMatrix(Sid.Gp).ToString(); //Sid.KeyGen(CodeType.Hamming, new[] { 3, 3 }); //this.txtbox_keys.Text = "\r\n\r\nr = 3, s = 3 \r\n\r\n Original: \r\n" + Code.DualCode(ham.G | ham.G | ham.G).ToString(); //this.txtbox_keys.Text += "\r\n Noised: \r\n" + Code.DualCode(Sid.N[0] * ham.G | Sid.N[1] * ham.G | Sid.N[2] * ham.G).ToString(); //this.txtbox_keys.Text += "\r\n Noised and permuted: \r\n" + Code.DualCode(Sid.Gp).ToString(); // form parameters this.FormBorderStyle = FormBorderStyle.FixedDialog; this.AutoScaleMode = AutoScaleMode.Dpi; this.AutoSize = false; this.MaximizeBox = false; this.StartPosition = FormStartPosition.CenterScreen; }
public double AttackRM(out Matrix N1, out Matrix P1, out List <int> I) { int k = Gp.size[0], nn = Gp.size[1]; Code code = new Code(Gp); int r = -1, m = 1, count = 0; while ((1 << (m + 1)) < nn) { ++m; } while (count < k) { ++r; count += Common.C(m, r); } Code code_attack; //2 * r >= m => consider the dual code if (2 * r < m) { code_attack = new Code(code.G); } else { code_attack = new Code(code.H); r = m - r - 1; } int n = (1 << m), l = nn - n; N1 = new Matrix(k, k); P1 = new Matrix(n, n); Stopwatch t = new Stopwatch(); t.Start(); I = new List <int>(); Code Li; int dim_square = Code.Square(code_attack).size[0], idx; List <int> check = Enumerable.Range(0, nn).ToList(); while (I.Count != l) { idx = Common.GetRand() % check.Count; Li = new Code(new Matrix(code_attack.G) ^ check[idx], false); if (Code.Square(Li).size[0] == dim_square - 1) { I.Add(check[idx]); } check.RemoveAt(idx); } //I = new List<int>(); Code Li; //int dim_square = Code.Square(code).size[0]; //for (int i = 0; i < nn; ++i) //{ // Li = new Code(new Matrix(code.G) ^ i, false); // if (Code.Square(Li).size[0] == dim_square - 1) // { // I.Add(i); // } // if (I.Count == l) break; //} t.Stop(); Matrix Tmp = new Matrix(code.G); int shift = 0; I.Sort(); for (int i = 0; i < l; ++i) { Tmp ^= I[i] - shift; ++shift; } McElice McE = new McElice(); McE.Gp = Tmp; McE.AttackRM(out N1, out P1); return(t.ElapsedMilliseconds / 1000.00); }