⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ep_s1.cs

📁 Encrypt and Decrypt with different algorithm. Can enter password for each file you encrypt.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EN11
{
    public partial class ep_s1 : Form
    {
        public ep_s1()
        {
            InitializeComponent();
        }
        int stpn = 0;
        string file;
        private void nuttnxt2_Click(object sender, EventArgs e)
        {
            if (stpn == 0)
            {
                if (infile.Text.Trim() == string.Empty || System.IO.File.Exists(infile.Text) == false)
                {
                    MessageBox.Show("You must select a valid file");
                }
                else
                {
                    
                    file = infile.Text;
                    infile.Text = "";
                    buttbrs.Visible = false;
                    infile.MaxLength = 4;
                    infile.PasswordChar = 'E';
                    lblin1.Text = "Enter the password";
                    nuttnxt2.Text = "&Finish";
                    stpn++;
                }
                goto k;
            }
            if (stpn == 1)
            {
                if (infile.Text.Trim() == string.Empty || infile.Text.Length < 4)
                {
                    MessageBox.Show("You must enter a password");
                }
                else
                {
                    lblin1.Text = "Encrypting; Please wait";
                    nuttnxt2.Enabled = false;
                    Pgrss.ProgressClass ep = new Pgrss.ProgressClass();
                    System.IO.StreamReader fi = new System.IO.StreamReader(file);
                    System.IO.StreamWriter fo = new System.IO.StreamWriter(string.Concat(file, "TEMP"));
                    System.IO.BinaryReader bi = new System.IO.BinaryReader(fi.BaseStream);
                    System.IO.BinaryWriter bo = new System.IO.BinaryWriter(fo.BaseStream);
                    ep.ShowProgressWindow();
                    Int64 counter = 0;
                     Byte bt;
                    string charcheck ="";
                    bi.BaseStream.Seek(1, System.IO.SeekOrigin.Begin);
                    while (!(counter == 6))
                    {
                        //bt = bi.ReadByte();
                        charcheck += bi.ReadChar(); 
                        counter += 1;
                    }
                    if (!(charcheck == "`enc` "))
                    {
                        fi.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                        bo.Write("`enc` ");
                        Letter_Crypt.Main_Letter_Crypt lc = new Letter_Crypt.Main_Letter_Crypt();
                        int pwc = 1;
                        string cp = "";
                        while (!(pwc == 5))
                        {
                            cp += lc.Crypt_Letter(infile.Text.Substring(pwc-1, 1).ToUpper());
                            pwc++;
                        }
                        bo.Write(cp);
                        counter = 0;
                        bt = 0;
                        for (counter =1;counter <= bi.BaseStream.Length; counter++ )
                        {
                            Application.DoEvents();
                            ep.SetProgressVal(counter, bi.BaseStream.Length);
                            bt = bi.ReadByte();
                            if (bt == 255) { bt = 0; }
                            else
                            {
                                bt += 1;
                            }
                            bo.Write(bt);
                        }
                        fi.Close();
                        fo.Close();
                        MessageBox.Show("Completed");
                        ep.CloseWindow();
                        System.IO.File.Delete(file);
                        System.IO.File.Move(string.Concat(file, "TEMP"), file);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("This file is already encrypted");
                        fi.Close();
                        fo.Close();
                        System.IO.File.Delete(string.Concat(file, "TEMP"));
                        this.Close();

                    }
                    ep.CloseWindow();

                }
            }
        k: { }
        }

        private void buttbrs_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog od = new OpenFileDialog();
            od.Filter = "All Files(*.*)|*.*";
            od.Title = "Open";
            od.ShowDialog ();
            infile.Text = od.FileName.Trim();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -