feat: added correct message padding

This commit is contained in:
citizen-VM 2020-08-21 20:10:07 +02:00
parent 66a8a00b13
commit 5ad4cbc7c3
Signed by: wanderer
GPG Key ID: 6391444A736EEE7E

View File

@ -49,9 +49,9 @@ namespace KRY_0x01_ng
{
second_char = 'Q';
}
else if ((i == str.Length || str[i] == first_char) && (first_char != 'W'))
else if ((i == str.Length || str[i] == first_char) && (first_char != 'Z'))
{
second_char = 'W';
second_char = 'Z';
}
else
{
@ -61,6 +61,10 @@ namespace KRY_0x01_ng
padded_str += first_char;
padded_str += second_char;
}
if (padded_str.Length % 2 != 0)
{
padded_str = pad(padded_str);
}
}
return padded_str;
}
@ -74,7 +78,7 @@ namespace KRY_0x01_ng
return;
}
string str_to_check = str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct());
string str_to_check = String.Join("", tb_k.Text.ToUpper().Distinct());
if (str_to_check.Length < 9)
{
MessageBox.Show($"The key is too short ({str_to_check.Length} characters).\nKey requirements: 9-25 unique alphabetic characters", "Error");
@ -93,7 +97,15 @@ namespace KRY_0x01_ng
return;
}
TextBox tb_pruned_k = textBox2;
TextBox tb_nualph = textBox3;
tb_pruned_k.Text = str_to_check;
nualphabet = alphabet.Except(str_to_check.ToArray()).ToArray();
string nualph_str = "";
for (int i = 0; i < nualphabet.Length; i++)
{
nualph_str += nualphabet[i];
}
tb_nualph.Text = str_to_check + nualph_str;
return;
}
@ -117,23 +129,8 @@ namespace KRY_0x01_ng
}
void prep_message(TextBox tb_m)
{
string msg = tb_m.Text;
if (msg.Length % 2 != 0)
{
if (! msg.EndsWith("X"))
{
msg += "X";
}
else if (! msg.EndsWith("Q"))
{
msg += "Q";
}
else if (! msg.EndsWith("Z"))
{
msg += "Z";
}
}
textBox6.Text = pad(msg);
string msg = pad(tb_m.Text);
textBox6.Text = msg;
return;
}