zoukankan      html  css  js  c++  java
  • 加密和解密算法 Asp.net

    1.aspx页面

     1     <div>
     2         <table>
     3             <tr>
     4                 <td>
     5                     <asp:Label ID="Label1" runat="server" Text="字符串" Font-Size="10pt"></asp:Label>
     6                 </td>
     7                 <td>
     8                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     9                 </td>
    10             </tr>
    11             <tr>
    12                 <td>
    13                     <asp:Label ID="Label2" runat="server" Text="加密解密" Font-Size="10pt"></asp:Label>
    14                 </td>
    15                 <td>
    16                     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    17                 </td>
    18             </tr>
    19             <tr>
    20                 <td colspan="2" align="center">
    21                     <asp:Button ID="Button1" runat="server" Text="加密" onclick="Button1_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
    22                     <asp:Button ID="Button2" runat="server" Text="解密" onclick="Button2_Click" />
    23                 </td>
    24             </tr>
    25         </table>
    26     </div>          

    2.cs页面

     1   protected void Button1_Click(object sender, EventArgs e)
     2     {
     3         TextBox2.Text = Encrypt(TextBox1.Text);
     4     }
     5     protected void Button2_Click(object sender, EventArgs e)
     6     {
     7         TextBox2.Text = Decryptor(TextBox2.Text);
     8     }
     9 
    10     private string Encrypt(string s)
    11     {
    12         Encoding ascii = Encoding.ASCII;
    13         string EncryptString;
    14         EncryptString = "";
    15         for (int i = 0; i < s.Length; i++)
    16         {
    17             int j;
    18             byte[] b = new byte[1];
    19             j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
    20             j = j + 5;
    21             b[0] = Convert.ToByte(j);
    22             EncryptString = EncryptString + ascii.GetString(b);
    23         }
    24         return EncryptString;
    25     }
    26     private string Decryptor(string s)
    27     {
    28         Encoding ascii = Encoding.ASCII;
    29         string DecryptorString;
    30         DecryptorString = "";
    31         for (int i = 0; i < s.Length; i++)
    32         {
    33             int j;
    34             byte[] b = new byte[1];
    35             j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
    36             j = j - 5;
    37             b[0] = Convert.ToByte(j);
    38             DecryptorString = DecryptorString + ascii.GetString(b);
    39         }
    40         return DecryptorString;  41     } 


    乌龟才背着房子过一辈子
  • 相关阅读:
    Android ListView带CheckBox实现单选
    android 登录和设置IP/端口功能
    html5 10大html5前端框架
    Html5 8个强大的基于Bootstrap的CSS框架
    Android 探究 LayoutInflater setFactory
    Android onLoadFinished与onLoaderReset
    Android android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
    Android 中AIDL的使用与理解
    Android Studio查看android源码
    ArrayList和LinkedList的用法区别:
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/3085486.html
Copyright © 2011-2022 走看看