diff --git a/main_form.Designer.cs b/main_form.Designer.cs index 4ccf18e..4f54587 100644 --- a/main_form.Designer.cs +++ b/main_form.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); @@ -223,14 +223,14 @@ this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.ColumnHeadersVisible = false; - dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle7.Font = new System.Drawing.Font("Verdana", 30F); - dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle7; + dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle9.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle9.Font = new System.Drawing.Font("Verdana", 30F); + dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle9.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle9; this.dataGridView1.Location = new System.Drawing.Point(401, 88); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; @@ -290,6 +290,7 @@ this.button3.TabIndex = 507; this.button3.Text = "check key"; this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); // // label11 // @@ -333,6 +334,7 @@ this.button4.TabIndex = 512; this.button4.Text = "decrypt"; this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); // // label13 // diff --git a/main_form.cs b/main_form.cs index 2ea720e..377b77e 100644 --- a/main_form.cs +++ b/main_form.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -71,7 +72,7 @@ namespace KRY_0x01_ng } - bool check_key(TextBox tb_k) + bool check_key(TextBox tb_k, TextBox tb_pk, TextBox tb_na) { bool success = true; if (tb_k.Text.Length == 0) @@ -100,8 +101,8 @@ namespace KRY_0x01_ng return success = false; } - TextBox tb_pruned_k = textBox2; - TextBox tb_nualph = textBox3; + TextBox tb_pruned_k = tb_pk; + TextBox tb_nualph = tb_na; tb_pruned_k.Text = str_to_check; char[] transient_alph = alphabet.Except(str_to_check.ToArray()).ToArray(); string transientalph_str = ""; @@ -167,6 +168,24 @@ namespace KRY_0x01_ng return; } + void check_cryptmessage(TextBox tb_m) + { + if (tb_m.Text.Length == 0) + { + MessageBox.Show("Empty message, nothing to do.", "Warning"); + return; + } + string msg = tb_m.Text.ToUpper(); + Match match = Regex.Match(msg, @"\d|\s+|W"); + if (match.Success) + { + 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; + } + textBox9.Text = msg; + return; + } + string msg_hack_up(string msg) { string digraph_msg = ""; @@ -207,7 +226,7 @@ namespace KRY_0x01_ng void encrypt() { - bool cool = check_key(textBox1); + bool cool = check_key(textBox1, textBox2, textBox3); if (!cool) { return; @@ -265,6 +284,19 @@ namespace KRY_0x01_ng + void decrypt() + { + bool cool = check_key(textBox8, textBox11, textBox10); + if (!cool) + { + return; + } + check_cryptmessage(textBox9); + } + + + + private void button1_Click(object sender, EventArgs e) { /* encrypt button */ @@ -274,12 +306,29 @@ namespace KRY_0x01_ng private void button2_Click(object sender, EventArgs e) { /* check key button */ - bool cool = check_key(textBox1); + bool cool = check_key(textBox1, textBox2, textBox3); if (!cool) { return; } fill_array_table(); } + + private void button3_Click(object sender, EventArgs e) + { + /* check decryption key*/ + bool cool = check_key(textBox8, textBox11, textBox10); + if (!cool) + { + return; + } + fill_array_table(); + } + + private void button4_Click(object sender, EventArgs e) + { + /* decrypt */ + decrypt(); + } } }