diff --git a/main_form.cs b/main_form.cs index cd5f136..689b7cc 100644 --- a/main_form.cs +++ b/main_form.cs @@ -71,12 +71,13 @@ namespace KRY_0x01_ng } - void check_key(TextBox tb_k) + bool check_key(TextBox tb_k) { + bool success = true; if (tb_k.Text.Length == 0) { MessageBox.Show("Empty key.", "Warning"); - return; + return success = false; } string str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct()); @@ -84,20 +85,21 @@ namespace KRY_0x01_ng { /* because why not, 8 is still lame */ MessageBox.Show($"The key is too short ({str_to_check.Length} characters).\nKey requirements: 9-25 unique alphabetic characters", "Error"); - return; + return success = false; } else if (str_to_check.Length > 25) { MessageBox.Show("The key is too long", "Warning"); - return; + return success = false; } Match match = Regex.Match(str_to_check, @"\d|\s+"); if (match.Success) { MessageBox.Show("Only alphabetic characters and spaces are allowed.\nCheck the key for numbers, symbols or tab whitespace and remove them before continuing.", "Error"); - return; + return success = false; } + TextBox tb_pruned_k = textBox2; TextBox tb_nualph = textBox3; tb_pruned_k.Text = str_to_check; @@ -110,8 +112,7 @@ namespace KRY_0x01_ng string nualph_str = str_to_check + transientalph_str; tb_nualph.Text = nualph_str; nualphabet = nualph_str.ToCharArray(); - fill_array_table(); - return; + return success; } @@ -206,6 +207,13 @@ namespace KRY_0x01_ng void encrypt() { + bool cool = check_key(textBox1); + if (!cool) + { + return; + } + + fill_array_table(); check_message(textBox4); prep_message(textBox5); @@ -266,7 +274,7 @@ namespace KRY_0x01_ng private void button2_Click(object sender, EventArgs e) { /* check key button */ - check_key(textBox1); + bool cool = check_key(textBox1); } } }