refactor: get rid of unnecessary value assignments

This commit is contained in:
citizen-VM 2020-08-24 21:12:48 +02:00
parent 27a73f94eb
commit 59605107c2
Signed by: wanderer
GPG Key ID: 6391444A736EEE7E

View File

@ -74,11 +74,10 @@ namespace KRY_0x01_ng
bool check_key(TextBox tb_k, TextBox tb_pk, TextBox tb_na) bool check_key(TextBox tb_k, TextBox tb_pk, TextBox tb_na)
{ {
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 success = false; return false;
} }
string str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct()); string str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct());
@ -86,19 +85,19 @@ 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 success = false; return 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 success = false; return 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 are allowed.\nCheck the key for numbers, symbols or tab whitespace and remove them before continuing.", "Error"); MessageBox.Show("Only alphabetic characters are allowed.\nCheck the key for numbers, symbols or tab whitespace and remove them before continuing.", "Error");
return success = false; return false;
} }
TextBox tb_pruned_k = tb_pk; TextBox tb_pruned_k = tb_pk;
@ -113,7 +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();
return success; return true;
} }
@ -231,8 +230,7 @@ namespace KRY_0x01_ng
void encrypt() void encrypt()
{ {
bool cool = check_key(textBox1, textBox2, textBox3); if (!check_key(textBox1, textBox2, textBox3))
if (!cool)
{ {
return; return;
} }
@ -291,8 +289,7 @@ namespace KRY_0x01_ng
void decrypt() void decrypt()
{ {
bool cool = check_key(textBox8, textBox11, textBox10); if(!check_key(textBox8, textBox11, textBox10))
if (!cool)
{ {
return; return;
} }