zoukankan      html  css  js  c++  java
  • Csharp and Vbscript: Encryption/Decryption Functional

      1 /// <summary>
      2     /// 塗聚文
      3     /// 20130621
      4     /// 自定义字符串加密解密
      5     /// </summary>
      6    public class DecEncClass
      7     {
      8         /// <summary>
      9         /// 
     10         /// 加密
     11         /// </summary>
     12         /// <param name="s"></param>
     13         /// <returns></returns>
     14         public string Enc(string s)
     15         {
     16        
     17              string str=@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/._ -,;涂聚文";
     18              string key = @"fokuq3FnR2HlcI9CSsL10myrdUpNbh7AjtXa65vQWPwYTZgBEDMOiG8xeVKJz4%!^_$-,;咭㙍塗";
     19              int strLen=str.Length;
     20              int keyLen=key.Length;    
     21              string returnStr;
     22              returnStr="";
     23     
     24             for(int i=0; i<s.Length;i++)
     25             {
     26                 for(int n=0; n<strLen;n++)
     27                 {
     28                     //1
     29                     //if (str.Substring(n, 1) == s.Substring(i, 1))//
     30                     //{
     31                     //    returnStr = returnStr + key.Substring(n, 1);
     32                     //    break;
     33                     //}
     34                     //2
     35                     if (Mid(str, n, 1) == Mid(s, i, 1))//
     36                     {
     37                         returnStr = returnStr + Mid(key, n, 1);
     38                         break;
     39                     }
     40                  }
     41             
     42             }
     43             //Enc=returnStr
     44             return returnStr;
     45         }
     46        /// <summary>
     47        /// 解密
     48        /// </summary>
     49        /// <param name="s"></param>
     50        /// <returns></returns>
     51         public string Dec(string s)
     52         {
     53             string str = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/._ -,;涂聚文";
     54             string key = @"fokuq3FnR2HlcI9CSsL10myrdUpNbh7AjtXa65vQWPwYTZgBEDMOiG8xeVKJz4%!^_$-,;咭㙍塗";
     55             int strLen=str.Length;
     56             int keyLen=key.Length;    
     57             string returnStr;
     58             returnStr = "";
     59             
     60             for(int i=0;i<s.Length;i++)
     61             {
     62                 for(int  n=0; n<keyLen;n++)
     63                 {
     64                     //1
     65                     //if (key.Substring(n, 1) == s.Substring(i, 1))
     66                     //{
     67                     //    returnStr = returnStr + str.Substring(n, 1);
     68                     //    break;
     69                     //    //exit for
     70                     //}
     71                     //2
     72                     if (Mid(key, n, 1) == Mid(s, i, 1))
     73                     {
     74                         returnStr = returnStr + Mid(str, n, 1);
     75 
     76                         break;
     77                         //exit for
     78                     }
     79                } 
     80             }            
     81                //Dec=returnStr;
     82               return returnStr;
     83       }
     84           /// <summary>
     85           /// 
     86           /// </summary>
     87           /// <param name="param"></param>
     88           /// <param name="length"></param>
     89           /// <returns></returns>
     90            public  string Left(string param, int length)
     91          {
     92              //we start at 0 since we want to get the characters starting from the
     93              //left and with the specified lenght and assign it to a variable
     94              string result = param.Substring(0, length);
     95              //return the result of the operation
     96              return result;
     97          } 
     98        /// <summary>
     99        /// 
    100        /// </summary>
    101        /// <param name="param"></param>
    102        /// <param name="length"></param>
    103        /// <returns></returns>
    104          public  string Right(string param, int length)
    105          {
    106              //start at the index based on the lenght of the sting minus
    107              //the specified lenght and assign it a variable
    108              string result = param.Substring(param.Length-length, length);
    109              //return the result of the operation
    110              return result;
    111          }
    112        /// <summary>
    113        /// 
    114        /// </summary>
    115        /// <param name="param"></param>
    116        /// <param name="startIndex"></param>
    117        /// <param name="length"></param>
    118        /// <returns></returns>
    119          public  string Mid(string param,int startIndex, int length)
    120          {
    121              string result = "";
    122              //start at the specified index in the string ang get N number of
    123              //characters depending on the lenght and assign it to a variable
    124              result = param.Substring(startIndex, length);
    125         
    126              //return the result of the operation
    127              return result;
    128          }
    129        /// <summary>
    130        /// 
    131        /// </summary>
    132        /// <param name="param"></param>
    133        /// <param name="startIndex"></param>
    134        /// <returns></returns>
    135          public  string Mid(string param,int startIndex)
    136          {
    137              //start at the specified index and return all characters after it
    138              //and assign it to a variable
    139              string result = param.Substring(startIndex);
    140              //return the result of the operation
    141              return result;
    142          }
    143     }

    vbscript:

     1 <%
     2 
     3 
     4 Function Enc(s)
     5  str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/._ -,;"
     6  key="fokuq3FnR2HlcI9CSsL10myrdUpNbh7AjtXa65vQWPwYTZgBEDMOiG8xeVKJz4%!^_$-,;"
     7     strLen=len(str)
     8     keyLen=len(key)
     9     
    10     dim returnStr
    11     returnStr=""
    12     
    13     for i=1 to len(s)
    14         for n=1 to strLen
    15             if mid(str,n,1)=mid(s,i,1then
    16                 returnStr=returnStr&mid(key,n,1)
    17                 exit for
    18             end if    
    19         next 
    20     next
    21     
    22     Enc=returnStr
    23 
    24 End Function
    25 
    26 Function Dec(s)
    27  str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/._ -,;"
    28  key="fokuq3FnR2HlcI9CSsL10myrdUpNbh7AjtXa65vQWPwYTZgBEDMOiG8xeVKJz4%!^_$-,;"
    29     strLen=len(str)
    30     keyLen=len(key)
    31     
    32     dim returnStr
    33     returnStr=""
    34     
    35     for i=1 to len(s)
    36         for n=1 to keyLen
    37             if mid(key,n,1)=mid(s,i,1then
    38                 returnStr=returnStr&mid(str,n,1)
    39                 exit for
    40             end if    
    41         next 
    42     next
    43     
    44     Dec=returnStr
    45 
    46 End Function
    47 
    48 %>

  • 相关阅读:
    重塑矩阵
    买卖股票
    两个数组的交集
    洛谷 P3700
    HDU 6987
    Solution -「NOI 2021」「洛谷 P7740」机器人游戏
    「NOI 2021」酱油记
    Solution -「UNR #5」「UOJ #671」诡异操作
    CD from Codeforces Round #703 (Div. 2)
    CD from Codeforces Round #701 (Div. 2)
  • 原文地址:https://www.cnblogs.com/geovindu/p/3148800.html
Copyright © 2011-2022 走看看