zoukankan      html  css  js  c++  java
  • 最简单的加密解密算法

     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 WindowsFormsApplication1
    11 {
    12     public partial class Form1 : Form
    13     {
    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         #endregion
    58         //解密
    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         #endregion
    77 
    78        
    79     }
    80 }

    加密:

    解密:

  • 相关阅读:
    String方法
    多态
    观察者模式
    ArrayList和LinkList
    唐岛湾
    AForge.Net C#的操作视频,照片读写功能
    JqGrid填坑
    日常点滴
    日常点滴
    EF Core 填坑记录
  • 原文地址:https://www.cnblogs.com/jason-davis/p/4047124.html
Copyright © 2011-2022 走看看