一个VBS的加密函数转换为C#

/*
   * //解密
   * function decrypt(dcode) 
   dim texts
   dim i
   for i=1 to len(dcode)
   texts=texts & chr(asc(mid(dcode,i,2))-i)
   next
   decrypt=texts
   end function
   //加密
   function encrypt(ecode)
   Dim texts
   dim i
   for i=1 to len(ecode)
   texts=texts & chr(asc(mid(ecode,i,2))+i)
   next
   encrypt = texts
   end function
   * */
  /// <summary>
  /// 字符串加密
  /// </summary>
  /// <param name="str">待加密的字符串</param>
  /// <returns></returns>
  public string encode(string str)
  {
   string htext = ""; // blank text

   for ( int i = 0; i < str.Length; i++)
   {
    htext = htext + (char) (str[i] + 10 - 1 * 2);
   }
   return htext;
  }

  /// <summary>
  /// 字符串解密
  /// </summary>
  /// <param name="str">待解密的字符串</param>
  /// <returns></returns>
  public string decode(string str)
  {
   string dtext = "";

   for ( int i=0; i < str.Length; i++)
   {
    dtext = dtext + (char) (str[i] - 10 + 1*2);
   }
   return dtext;
  }

posted on 2005-11-16 10:21  冷月孤峰  阅读(246)  评论(0)    收藏  举报