private void checkMN() { try { knapsack.M = Int32.Parse(textBox2.Text); knapsack.N = Int32.Parse(textBox4.Text); if (TheKnapsackProblemCipher.GCD(knapsack.N, knapsack.M) == 1) { label8.BackColor = Color.LawnGreen; } else { label8.BackColor = Color.Tomato; } int sumOfAll = TheKnapsackProblemCipher.CountSumOfPrev(knapsack.PrivateKey); label7.Text = "(> " + sumOfAll + " )"; if (knapsack.M > sumOfAll) { label7.BackColor = Color.LawnGreen; } else { label7.BackColor = Color.Tomato; } } catch { knapsack.M = knapsack.N = 0; MessageBox.Show("M, N are numbers!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void textBox1_TextChanged(object sender, EventArgs e) { try { int i = 0; knapsack.PrivateKey = new int[textBox1.Text.Split(' ').Length]; foreach (var item in textBox1.Text.Split(' ')) { if (item != "") { knapsack.PrivateKey[i++] = Int32.Parse(item); } } knapsack.RegeneratePublicKey(); PublicKey = knapsack.PublicKey; M = TheKnapsackProblemCipher.CountSumOfPrev(PrivateKey) + 1; checkMN(); } catch { knapsack.PrivateKey = knapsack.PublicKey = null; MessageBox.Show("Key should consist numbers, seperated by space!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }