?? encrypt.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Encrypt
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button decryptbutton;
private System.Windows.Forms.Button encryptbutton;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton plainButton;
private System.Windows.Forms.RadioButton cypherButton;
private System.Windows.Forms.TextBox plaintext;
private System.Windows.Forms.TextBox cyphertext;
private System.Windows.Forms.Button Quit;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox IncValue;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.Quit = new System.Windows.Forms.Button();
this.IncValue = new System.Windows.Forms.TextBox();
this.cyphertext = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.plainButton = new System.Windows.Forms.RadioButton();
this.cypherButton = new System.Windows.Forms.RadioButton();
this.decryptbutton = new System.Windows.Forms.Button();
this.encryptbutton = new System.Windows.Forms.Button();
this.plaintext = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.Quit,
this.IncValue,
this.cyphertext,
this.groupBox2,
this.decryptbutton,
this.encryptbutton,
this.plaintext});
this.groupBox1.Location = new System.Drawing.Point(8, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(312, 120);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(176, 32);
this.label1.TabIndex = 20;
this.label1.Text = "Please Enter the Value by which you want to decrypt/encrypt by:";
//
// Quit
//
this.Quit.Location = new System.Drawing.Point(232, 80);
this.Quit.Name = "Quit";
this.Quit.Size = new System.Drawing.Size(72, 24);
this.Quit.TabIndex = 19;
this.Quit.Text = "&Quit";
this.Quit.Click += new System.EventHandler(this.Quit_Click);
//
// IncValue
//
this.IncValue.Location = new System.Drawing.Point(192, 88);
this.IncValue.Name = "IncValue";
this.IncValue.Size = new System.Drawing.Size(24, 20);
this.IncValue.TabIndex = 18;
this.IncValue.Text = "";
this.IncValue.TextChanged += new System.EventHandler(this.IncValue_TextChanged_1);
//
// cyphertext
//
this.cyphertext.Location = new System.Drawing.Point(120, 48);
this.cyphertext.Name = "cyphertext";
this.cyphertext.Size = new System.Drawing.Size(104, 20);
this.cyphertext.TabIndex = 17;
this.cyphertext.Text = "Decrypted Message";
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.plainButton,
this.cypherButton});
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(112, 80);
this.groupBox2.TabIndex = 16;
this.groupBox2.TabStop = false;
//
// plainButton
//
this.plainButton.Checked = true;
this.plainButton.Location = new System.Drawing.Point(16, 16);
this.plainButton.Name = "plainButton";
this.plainButton.Size = new System.Drawing.Size(80, 24);
this.plainButton.TabIndex = 2;
this.plainButton.TabStop = true;
this.plainButton.Text = "PlainText";
this.plainButton.CheckedChanged += new System.EventHandler(this.plainButton_CheckedChanged);
//
// cypherButton
//
this.cypherButton.Location = new System.Drawing.Point(16, 48);
this.cypherButton.Name = "cypherButton";
this.cypherButton.Size = new System.Drawing.Size(88, 24);
this.cypherButton.TabIndex = 3;
this.cypherButton.Text = "CypherText";
this.cypherButton.CheckedChanged += new System.EventHandler(this.cypherButton_CheckedChanged);
//
// decryptbutton
//
this.decryptbutton.Location = new System.Drawing.Point(232, 48);
this.decryptbutton.Name = "decryptbutton";
this.decryptbutton.TabIndex = 13;
this.decryptbutton.Text = "&Decrypt";
this.decryptbutton.Click += new System.EventHandler(this.decryptbutton_Click);
//
// encryptbutton
//
this.encryptbutton.Location = new System.Drawing.Point(232, 16);
this.encryptbutton.Name = "encryptbutton";
this.encryptbutton.TabIndex = 14;
this.encryptbutton.Text = "&Encrypt";
this.encryptbutton.Click += new System.EventHandler(this.encryptbutton_Click);
//
// plaintext
//
this.plaintext.Location = new System.Drawing.Point(120, 16);
this.plaintext.Name = "plaintext";
this.plaintext.Size = new System.Drawing.Size(104, 20);
this.plaintext.TabIndex = 12;
this.plaintext.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 121);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1});
this.Location = new System.Drawing.Point(120, 48);
this.Name = "Form1";
this.Text = "Encrypt / Decrypt Program";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.plaintext.Enabled = true;
this.cyphertext.Enabled = false;
this.encryptbutton.Enabled = true;
this.decryptbutton.Enabled = false;
}
private void plainButton_CheckedChanged(object sender, System.EventArgs e)
{
this.plaintext.Enabled = true;
this.plaintext.Text = "";
this.cyphertext.Enabled = false;
this.encryptbutton.Enabled = true;
this.decryptbutton.Enabled = false;
this.cyphertext.Text = "Encrypted Message";
this.plaintext.Focus();
this.IncValue.Text = "";
}
private void cypherButton_CheckedChanged(object sender, System.EventArgs e)
{
this.cyphertext.Text = "";
this.plaintext.Enabled = false;
this.cyphertext.Enabled = true;
this.encryptbutton.Enabled = false;
this.decryptbutton.Enabled = true;
this.plaintext.Text = "Decrypted Message";
this.cyphertext.Focus();
this.IncValue.Text = "";
}
private void decryptbutton_Click(object sender, System.EventArgs e)
{
Decryption decrypt = new Decryption();
string temp = "";
if(this.cyphertext.Text == "")
{
MessageBox.Show("Cannot Decrypt - no cyphertext entered!");
this.cyphertext.Focus();
}
else
try
{
temp = decrypt.Decrypt(this.cyphertext.Text, this.IncValue.Text);
this.plaintext.Text = temp;
}
catch(Exception excep)
{
string type = excep.GetType().ToString();
if(type == "System.FormatException")
{
MessageBox.Show("Please Enter in a value by which to Decrypt by");
this.IncValue.Focus();
this.IncValue.Text = "";
System.Console.WriteLine("The following is a detailed description of the error\n" + type);
}
else if(type == "System.OverflowException")
{
MessageBox.Show("Number to large to encrypt, please enter in another number");
this.IncValue.Focus();
this.IncValue.Text = "";
System.Console.WriteLine("The following is a detailed description of the error\n" + type);
}
else
{
MessageBox.Show("Unexpected Exception");
System.Console.WriteLine("The following is a detailed description of the error\n" + type);
}
}
}
private void encryptbutton_Click(object sender, System.EventArgs e)
{
Encryption encrypt = new Encryption();
string temp = "";
if(this.plaintext.Text == "")
{
MessageBox.Show("Cannot Encrypt - No Plaintext entered");
this.plaintext.Focus();
}
else
try
{
temp = encrypt.Encrypt(this.plaintext.Text, this.IncValue.Text);
cyphertext.Text = temp;
}
catch(FormatException fexcept)
{
MessageBox.Show("Please enter in a numeric value by which to Encrypt by");
string tempex = fexcept.ToString();
this.IncValue.Text = "";
this.IncValue.Focus();
System.Console.WriteLine("The following is a detailed description of the error\n" + tempex);
}
catch(OverflowException overex)
{
MessageBox.Show("Number to large to encrypt, please enter in another number");
string tempex = overex.ToString();
this.IncValue.Text = "";
this.IncValue.Focus();
System.Console.WriteLine("The following is a detailed description of the error\n" + tempex);
}
}
private void Quit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void IncValue_TextChanged(object sender, System.EventArgs e)
{
if(this.IncValue.Text == "")
{
MessageBox.Show("Please Enter in a value by which to Encrypt/Decrypt by");
}
}
private void IncValue_TextChanged_1(object sender, System.EventArgs e)
{/*
if(! this.IncValue.Text.StartsWith("1"))
{
MessageBox.Show("woops");
}*/
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -