首页 > 代码库 > 最简单的加密解密算法

最简单的加密解密算法

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace WindowsFormsApplication111 {12     public partial class Form1 : Form13     {14         public Form1()15         {16             InitializeComponent();17         }18 19         private void Form1_Load(object sender, EventArgs e)20         {21             22         }23 24         private void button1_Click(object sender, EventArgs e)25         {26             //加密27             string s = this.textBox1.Text; 28             string ss= Encrypt(s);29             this.textBox2.Text = ss;30 31         }32         private void button2_Click(object sender, EventArgs e)33         {34             //解密35             string s = this.textBox1.Text;36             string ss = Decryptor(s);37             this.textBox2.Text = ss;38             39         }40         #region 加密41         public string Encrypt(string s)42         {43             Encoding ascii = Encoding.ASCII;//实例化。44             string EncryptString = "";//定义。45             for (int i = 0; i < s.Length; i++)//遍历。46             {47                 int j;48                 byte[] b = new byte[1];49                 j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);//获取字符的ASCII。50                 j = j + 5;//加密51                 b[0] = Convert.ToByte(j);//转换为八位无符号整数。52                 EncryptString = EncryptString + ascii.GetString(b);//显示。53 54             }55             return EncryptString;56         } 57         #endregion58         //解密59         #region 解密60         public string Decryptor(string s)61         {62             Encoding ascii = Encoding.ASCII;//实例化。63             string DecryptorString = "";//定义。64             for (int i = 0; i < s.Length; i++)//遍历。65             {66                 int j;67                 byte[] b = new byte[1];68                 j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);//获取字符的ASCII。69                 j = j - 5;//解密70                 b[0] = Convert.ToByte(j);//转换为八位无符号整数。71                 DecryptorString = DecryptorString + ascii.GetString(b);//显示。72 73             }74             return DecryptorString;75         } 76         #endregion77 78        79     }80 }

加密:

解密:

 

最简单的加密解密算法