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 System.IO;

namespace EncryptDecryptFiles
{
    public partial class frm44EncryptDecryptFiles : Form
    {
        public frm44EncryptDecryptFiles()
        {
            InitializeComponent();
        }

        private void frm44EncryptDecryptFiles_Load(object sender, EventArgs e)
        {
            filenameTextBox.Text = Application.StartupPath + "\\plaintext.txt";
        }

        // Encrypt and then decrypt the file.
        private void goButton_Click(object sender, EventArgs e)
        {
            string plainfile = filenameTextBox.Text;
            string cipherfile = Path.GetDirectoryName(plainfile) + "\\ciphertext.dat";
            string decipheredfile = Path.GetDirectoryName(plainfile) + "\\deciphered.txt";

            // Display the original file.
            plaintextTextBox.Text = File.ReadAllText(plainfile);

            // Encrypt the file.
            CryptoStuff.EncryptFile(passwordTextBox.Text, plainfile, cipherfile);
            ciphertextTextBox.Text = File.ReadAllBytes(cipherfile).ToHex(" ");

            // Decrypt the file.
            CryptoStuff.DecryptFile(passwordTextBox.Text, cipherfile, decipheredfile);
            decipheredTextBox.Text = File.ReadAllText(decipheredfile);
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (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.decipheredTextBox = new System.Windows.Forms.TextBox();
            this.ciphertextTextBox = new System.Windows.Forms.TextBox();
            this.plaintextTextBox = new System.Windows.Forms.TextBox();
            this.passwordTextBox = new System.Windows.Forms.TextBox();
            this.Label3 = new System.Windows.Forms.Label();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.tabPage3 = new System.Windows.Forms.TabPage();
            this.goButton = new System.Windows.Forms.Button();
            this.filenameTextBox = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.tabControl1.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabPage2.SuspendLayout();
            this.tabPage3.SuspendLayout();
            this.SuspendLayout();
            // 
            // decipheredTextBox
            // 
            this.decipheredTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.decipheredTextBox.Location = new System.Drawing.Point(3, 3);
            this.decipheredTextBox.Margin = new System.Windows.Forms.Padding(0, 2, 3, 3);
            this.decipheredTextBox.Multiline = true;
            this.decipheredTextBox.Name = "decipheredTextBox";
            this.decipheredTextBox.ReadOnly = true;
            this.decipheredTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.decipheredTextBox.Size = new System.Drawing.Size(298, 151);
            this.decipheredTextBox.TabIndex = 91;
            // 
            // ciphertextTextBox
            // 
            this.ciphertextTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ciphertextTextBox.Font = new System.Drawing.Font("Courier New", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ciphertextTextBox.Location = new System.Drawing.Point(3, 3);
            this.ciphertextTextBox.Margin = new System.Windows.Forms.Padding(0, 2, 3, 3);
            this.ciphertextTextBox.Multiline = true;
            this.ciphertextTextBox.Name = "ciphertextTextBox";
            this.ciphertextTextBox.ReadOnly = true;
            this.ciphertextTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.ciphertextTextBox.Size = new System.Drawing.Size(298, 151);
            this.ciphertextTextBox.TabIndex = 90;
            // 
            // plaintextTextBox
            // 
            this.plaintextTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.plaintextTextBox.Location = new System.Drawing.Point(3, 3);
            this.plaintextTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 3);
            this.plaintextTextBox.Multiline = true;
            this.plaintextTextBox.Name = "plaintextTextBox";
            this.plaintextTextBox.ReadOnly = true;
            this.plaintextTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.plaintextTextBox.Size = new System.Drawing.Size(298, 151);
            this.plaintextTextBox.TabIndex = 89;
            // 
            // passwordTextBox
            // 
            this.passwordTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.passwordTextBox.Location = new System.Drawing.Point(69, 38);
            this.passwordTextBox.Name = "passwordTextBox";
            this.passwordTextBox.Size = new System.Drawing.Size(172, 20);
            this.passwordTextBox.TabIndex = 1;
            this.passwordTextBox.Text = "The quick brown fox jumps over the lazy dog";
            // 
            // Label3
            // 
            this.Label3.AutoSize = true;
            this.Label3.Location = new System.Drawing.Point(7, 41);
            this.Label3.Name = "Label3";
            this.Label3.Size = new System.Drawing.Size(56, 13);
            this.Label3.TabIndex = 87;
            this.Label3.Text = "Password:";
            // 
            // tabControl1
            // 
            this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Controls.Add(this.tabPage3);
            this.tabControl1.Location = new System.Drawing.Point(10, 66);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(312, 183);
            this.tabControl1.TabIndex = 3;
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.plaintextTextBox);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(304, 157);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Original";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // tabPage2
            // 
            this.tabPage2.Controls.Add(this.ciphertextTextBox);
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(304, 157);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "Encrypted";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // tabPage3
            // 
            this.tabPage3.Controls.Add(this.decipheredTextBox);
            this.tabPage3.Location = new System.Drawing.Point(4, 22);
            this.tabPage3.Name = "tabPage3";
            this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage3.Size = new System.Drawing.Size(304, 157);
            this.tabPage3.TabIndex = 2;
            this.tabPage3.Text = "Decrypted";
            this.tabPage3.UseVisualStyleBackColor = true;
            // 
            // goButton
            // 
            this.goButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.goButton.Location = new System.Drawing.Point(247, 25);
            this.goButton.Name = "goButton";
            this.goButton.Size = new System.Drawing.Size(75, 23);
            this.goButton.TabIndex = 2;
            this.goButton.Text = "Go";
            this.goButton.UseVisualStyleBackColor = true;
            this.goButton.Click += new System.EventHandler(this.goButton_Click);
            // 
            // filenameTextBox
            // 
            this.filenameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.filenameTextBox.Location = new System.Drawing.Point(69, 12);
            this.filenameTextBox.Name = "filenameTextBox";
            this.filenameTextBox.Size = new System.Drawing.Size(172, 20);
            this.filenameTextBox.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(11, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(26, 13);
            this.label1.TabIndex = 95;
            this.label1.Text = "File:";
            // 
            // frm44EncryptDecryptFiles
            // 
            this.AcceptButton = this.goButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(334, 261);
            this.Controls.Add(this.filenameTextBox);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.goButton);
            this.Controls.Add(this.tabControl1);
            this.Controls.Add(this.passwordTextBox);
            this.Controls.Add(this.Label3);
            this.Name = "frm44EncryptDecryptFiles";
            this.Text = "EncryptDecryptFiles";
            this.Load += new System.EventHandler(this.frm44EncryptDecryptFiles_Load);
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            this.tabPage2.PerformLayout();
            this.tabPage3.ResumeLayout(false);
            this.tabPage3.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        internal System.Windows.Forms.TextBox decipheredTextBox;
        internal System.Windows.Forms.TextBox ciphertextTextBox;
        internal System.Windows.Forms.TextBox plaintextTextBox;
        internal System.Windows.Forms.TextBox passwordTextBox;
        internal System.Windows.Forms.Label Label3;
        private System.Windows.Forms.TabControl tabControl1;
        private System.Windows.Forms.TabPage tabPage1;
        private System.Windows.Forms.TabPage tabPage2;
        private System.Windows.Forms.TabPage tabPage3;
        private System.Windows.Forms.Button goButton;
        internal System.Windows.Forms.TextBox filenameTextBox;
        internal System.Windows.Forms.Label label1;
    }
}