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

📄 dc_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 dc_s1 : Form
    {
        public dc_s1()
        {
            InitializeComponent();
        }
        Pgrss.ProgressClass pb = new Pgrss.ProgressClass();


        private void dc_s1_Load(object sender, EventArgs e)
        {

        }
        int stpnn = 0;
        string filee="";
        private void nuttnxt2_Click(object sender, EventArgs e)
        {
               if (stpnn == 0)
            {
                if (infilex.Text.Trim() == string.Empty || System.IO.File.Exists(infilex.Text) == false)
                {
                    MessageBox.Show("You must select a valid file");
                }
                else
                {
                    filee = infilex.Text;
                    infilex.Text = "";
                    buttbrsf.Visible = false;
                    infilex.MaxLength = 4;
                    infilex.PasswordChar = 'D';
                    lblin2.Text = "Enter the password";
                    nuttnxt1.Text = "&Finish";
                    stpnn++;
                }
                goto kk;
            }
            if (stpnn == 1)
            {
                if (infilex.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("You must enter a password");
                }
                else
                {
                    System.IO.StreamReader fi = new System.IO.StreamReader(filee);
                    System.IO.StreamWriter fo = new System.IO.StreamWriter(string.Concat(filee, "TEMP"));
                    System.IO.BinaryReader bi = new System.IO.BinaryReader(fi.BaseStream);
                    System.IO.BinaryWriter bo = new System.IO.BinaryWriter(fo.BaseStream);
                    Int64 counterr = 0;
                     Byte btt;
                    string charcheckk ="";
                    bi.BaseStream.Seek(1, System.IO.SeekOrigin.Begin);
                    while (!(counterr == 6))
                    {
                        //bt = bi.ReadByte();
                        charcheckk += bi.ReadChar(); 
                        counterr += 1;
                    }
                    if ((charcheckk == "`enc` "))
                    {
                        fi.BaseStream.Seek(1, System.IO.SeekOrigin.Current);
                        Letter_Crypt.Main_Letter_Crypt lc = new Letter_Crypt.Main_Letter_Crypt();
                        int pwc = 1;
                        string cp = "";
                        while (!(pwc == 5))
                        {
                            cp += lc.DeCryptLetter(bi.ReadChar().ToString());
                            pwc++;
                        }
                        if (cp == infilex.Text.ToUpper())
                        {
                            lblin2.Text = "Decrypting; Please wait";
                            nuttnxt1.Enabled = false;
                            pb.ShowProgressWindow();
                            counterr = 0;
                            btt = 0;
                            for (counterr = 1; counterr <= bi.BaseStream.Length - 12;counterr++ )
                            {
                                Application.DoEvents();
                                pb.SetProgressVal(counterr, bi.BaseStream.Length);
                                btt = bi.ReadByte();
                                if (btt == 0) { btt = 255; }
                                else
                                {
                                    btt -= 1;
                                }
                                bo.Write(btt);
                                
                            }
                            fi.Close();
                            fo.Close();
                            MessageBox.Show("Completed");
                            System.IO.File.Delete(filee); 
                            System.IO.File.Move(string.Concat(filee, "TEMP"), filee);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Invalid Password");
                          
                            fi.Close();
                            fo.Close();
                            System.IO.File.Delete(string.Concat(filee, "TEMP"));
                            goto kk;
                           
                        }
                    }
                    else
                    {
                        MessageBox.Show("This file is not encrypted");
                        this.Close();
                       
                    }

                    pb.CloseWindow();
                }
            }
    
        kk: { }
           }

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

        private void infilex_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

⌨️ 快捷键说明

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