144 lines
4.6 KiB
Plaintext
144 lines
4.6 KiB
Plaintext
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using BlowFishCS;
|
|
using System.Configuration;
|
|
|
|
namespace BlowfishApplet
|
|
{
|
|
public partial class mainForm : Form
|
|
{
|
|
public mainForm()
|
|
{
|
|
InitializeComponent();
|
|
settingButton.BackColor = Properties.Settings.Default.myColor;
|
|
aboutButton.BackColor = Properties.Settings.Default.myColor;
|
|
encryptButton.BackColor = Properties.Settings.Default.myColor;
|
|
decryptButton.BackColor = Properties.Settings.Default.myColor;
|
|
resetButton.BackColor = Properties.Settings.Default.myColor;
|
|
swapButton.BackColor = Properties.Settings.Default.myColor;
|
|
divider1.BackColor = Properties.Settings.Default.myColor;
|
|
divider2.BackColor = Properties.Settings.Default.myColor;
|
|
divider3.BackColor = Properties.Settings.Default.myColor;
|
|
divider4.BackColor = Properties.Settings.Default.myColor;
|
|
}
|
|
|
|
private void settingButton_Click(object sender, EventArgs e)
|
|
{
|
|
settingsForm form = new settingsForm();
|
|
form.Show();
|
|
}
|
|
|
|
private void aboutButton_Click(object sender, EventArgs e)
|
|
{
|
|
aboutForm form = new aboutForm();
|
|
form.Show();
|
|
}
|
|
|
|
private void encryptButton_Click(object sender, EventArgs e)
|
|
{
|
|
String key = keyBox.Text;
|
|
String plain = inputBox.Text;
|
|
if (checkBoxes())
|
|
{
|
|
BlowFish c = new BlowFish(key);
|
|
string cipherText = "";
|
|
|
|
if (Properties.Settings.Default.cryptType == "CBC")
|
|
{
|
|
cipherText = c.Encrypt_CBC(plain);
|
|
}
|
|
else if (Properties.Settings.Default.cryptType == "ECB")
|
|
{
|
|
cipherText = c.Encrypt_ECB(plain);
|
|
}
|
|
else if (Properties.Settings.Default.cryptType == "CTR")
|
|
{
|
|
cipherText = c.Encrypt_CTR(plain);
|
|
}
|
|
|
|
outputBox.Text = cipherText;
|
|
}
|
|
}
|
|
|
|
private void decryptButton_Click(object sender, EventArgs e)
|
|
{
|
|
String key = keyBox.Text;
|
|
String cipherText = inputBox.Text;
|
|
|
|
if (checkBoxes())
|
|
{
|
|
BlowFish d = new BlowFish(key);
|
|
string plain = "";
|
|
|
|
if (Properties.Settings.Default.cryptType == "CBC")
|
|
{
|
|
plain = d.Decrypt_CBC(cipherText);
|
|
}
|
|
else if (Properties.Settings.Default.cryptType == "ECB")
|
|
{
|
|
plain = d.Decrypt_ECB(cipherText);
|
|
}
|
|
else if (Properties.Settings.Default.cryptType == "CTR")
|
|
{
|
|
plain = d.Decrypt_CTR(cipherText);
|
|
}
|
|
outputBox.Text = plain;
|
|
}
|
|
|
|
}
|
|
|
|
private void swapButton_Click(object sender, EventArgs e)
|
|
{
|
|
String text = outputBox.Text;
|
|
inputBox.Text = text;
|
|
outputBox.Text = "";
|
|
}
|
|
|
|
private Boolean checkBoxes()
|
|
{
|
|
keyBox.BackColor = System.Drawing.SystemColors.ScrollBar;
|
|
inputBox.BackColor = System.Drawing.SystemColors.ScrollBar;
|
|
|
|
Boolean noFill = true;
|
|
if (keyBox.Text == "")
|
|
{
|
|
keyBox.BackColor = System.Drawing.Color.Tomato;
|
|
noFill = false;
|
|
}
|
|
if (inputBox.Text == "")
|
|
{
|
|
inputBox.BackColor = System.Drawing.Color.Tomato;
|
|
noFill = false;
|
|
}
|
|
|
|
return noFill;
|
|
}
|
|
|
|
private void resetButton_Click(object sender, EventArgs e)
|
|
{
|
|
keyBox.BackColor = System.Drawing.SystemColors.ScrollBar;
|
|
inputBox.BackColor = System.Drawing.SystemColors.ScrollBar;
|
|
inputBox.Text = "";
|
|
keyBox.Text = "";
|
|
outputBox.Text = "";
|
|
}
|
|
|
|
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Properties.Settings.Default.posX = this.Left;
|
|
Properties.Settings.Default.posY = this.Top;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|