refactor: report status more accurately + move a metod call
This commit is contained in:
parent
ee83545f17
commit
42b0493218
24
main_form.cs
24
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)
|
if (tb_k.Text.Length == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Empty key.", "Warning");
|
MessageBox.Show("Empty key.", "Warning");
|
||||||
return;
|
return success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct());
|
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 */
|
/* 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");
|
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)
|
else if (str_to_check.Length > 25)
|
||||||
{
|
{
|
||||||
MessageBox.Show("The key is too long", "Warning");
|
MessageBox.Show("The key is too long", "Warning");
|
||||||
return;
|
return success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Match match = Regex.Match(str_to_check, @"\d|\s+");
|
Match match = Regex.Match(str_to_check, @"\d|\s+");
|
||||||
if (match.Success)
|
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");
|
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_pruned_k = textBox2;
|
||||||
TextBox tb_nualph = textBox3;
|
TextBox tb_nualph = textBox3;
|
||||||
tb_pruned_k.Text = str_to_check;
|
tb_pruned_k.Text = str_to_check;
|
||||||
|
@ -110,8 +112,7 @@ namespace KRY_0x01_ng
|
||||||
string nualph_str = str_to_check + transientalph_str;
|
string nualph_str = str_to_check + transientalph_str;
|
||||||
tb_nualph.Text = nualph_str;
|
tb_nualph.Text = nualph_str;
|
||||||
nualphabet = nualph_str.ToCharArray();
|
nualphabet = nualph_str.ToCharArray();
|
||||||
fill_array_table();
|
return success;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,6 +207,13 @@ namespace KRY_0x01_ng
|
||||||
|
|
||||||
void encrypt()
|
void encrypt()
|
||||||
{
|
{
|
||||||
|
bool cool = check_key(textBox1);
|
||||||
|
if (!cool)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fill_array_table();
|
||||||
check_message(textBox4);
|
check_message(textBox4);
|
||||||
prep_message(textBox5);
|
prep_message(textBox5);
|
||||||
|
|
||||||
|
@ -266,7 +274,7 @@ namespace KRY_0x01_ng
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void button2_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
/* check key button */
|
/* check key button */
|
||||||
check_key(textBox1);
|
bool cool = check_key(textBox1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue