KRY-0x01-ng/main_form.cs

111 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KRY_0x01_ng
{
public partial class main_form : Form
{
public main_form()
{
InitializeComponent();
}
char[,] arrayTable = new char[5, 5];
char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVXYZ".ToCharArray(); // no W
char[] nualphabet = new char[25];
public string prune_input(TextBox tb)
{
string str = tb.Text.ToUpper();
string alpha_str = Regex.Replace(str, " ", "MEZERABRO");
alpha_str = alpha_str.Replace("[^A-Z]+", "");
return alpha_str.Replace("W", "V");
}
public string restore_order(string str)
{
string alpha_str = Regex.Replace(str, "MEZERABRO", " ");
return alpha_str;
}
public string pad(string str)
{
string padded_str = "";
if (str.Length > 0)
{
int i = 0;
while (i < str.Length)
{
char first_char = str[i];
i++;
char second_char;
if ((i == str.Length || str[i] == first_char) && (first_char != 'X'))
{
second_char = 'X';
}
else if ((i == str.Length || str[i] == first_char) && (first_char != 'Q'))
{
second_char = 'Q';
}
else if ((i == str.Length || str[i] == first_char) && (first_char != 'W'))
{
second_char = 'W';
}
else
{
second_char = str[i];
i++;
}
padded_str += first_char;
padded_str += second_char;
}
}
return padded_str;
}
void check_key()
{
return;
}
void check_message(TextBox tb_m)
{
string msg = pad(tb_m.Text);
return;
}
void encrypt()
{
string cryptmessage = "";
string m_text = prune_input(textBox4);
return;
}
private void button1_Click(object sender, EventArgs e)
{
/* encrypt button */
check_message(textBox4);
encrypt();
}
private void button2_Click(object sender, EventArgs e)
{
/* check key button */
check_key();
}
}
}