diff --git a/main_form.cs b/main_form.cs index 377b77e..d7fcafd 100644 --- a/main_form.cs +++ b/main_form.cs @@ -182,6 +182,11 @@ namespace KRY_0x01_ng MessageBox.Show("Only alphabetic characters (with the exception of W) are allowed.\nCheck the cryptmessage for numbers, symbols or tab whitespace and remove them before continuing.", "Error"); return; } + if (tb_m.Text.Length % 2 != 0) + { + MessageBox.Show("This pretty sure can't be a message I can deal with (uneven number of characters).", "Error"); + return; + } textBox9.Text = msg; return; } @@ -291,7 +296,43 @@ namespace KRY_0x01_ng { return; } + fill_array_table(); check_cryptmessage(textBox9); + + string message = ""; + string crm = textBox9.Text; + int arrtb_gl = arrayTable.GetLength(0); + for (int i = 0; i < crm.Length; i+=2) + { + char ch1 = crm[i]; + char ch2 = crm[i + 1]; + char ech1; + char ech2; + int[] ch1xy = gimme_char_indices(ch1); + int[] ch2xy = gimme_char_indices(ch2); + + if (ch1xy[0] == ch2xy[0]) + { + /* c# neg modulo issue hack */ + ech1 = arrayTable[ch1xy[0], (ch1xy[1] + 4) % arrtb_gl]; + ech2 = arrayTable[ch2xy[0], (ch2xy[1] + 4) % arrtb_gl]; + } + else if (ch1xy[1] == ch2xy[1]) + { + ech1 = arrayTable[(ch1xy[0] + 4) % arrtb_gl, ch1xy[1]]; + ech2 = arrayTable[(ch2xy[0] + 4) % arrtb_gl, ch2xy[1]]; + } + else + { + ech1 = arrayTable[ch1xy[0], ch2xy[1]]; + ech2 = arrayTable[ch2xy[0], ch1xy[1]]; + } + + string resulting_digraph = ech1.ToString() + ech2.ToString(); + message += resulting_digraph; + } + textBox12.Text = message; + return; }