简单的字符串加密/解密类

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    /// <summary>
    /// 简单的字符串加密/解密类
    /// </summary>
    public class Key
    {
        /// <summary>
        /// 字符串加密
        /// </summary>
        /// <param name="str">待加密字符串</param>
        /// <returns></returns>
        public static String Encode(String str)
        {
            int[] strpw = { 1, 3, 7, 0, 5, 9, 1, 0, 6, 2, 4 };
            string newstr = "";
            for (int i = 0; i < str.Length; i++)
            {
                char c = str[i];
                c += (char)strpw[i % strpw.Length];
                newstr += c;
            }
            return newstr;
        }

        /// <summary>
        /// 字符串解密
        /// </summary>
        /// <param name="str">待解密字符串</param>
        /// <returns></returns>
        public static String Decode(String str)
        {
            int[] strpw = { 1, 3, 7, 0, 5, 9, 1, 0, 6, 2, 4 };
            string newstr = "";
            for (int i = 0; i < str.Length; i++)
            {
                char c = str[i];
                c -= (char)strpw[i % strpw.Length];
                newstr += c;
            }
            return newstr;
        }
    }
}


评论: 0 | 引用: 0 | 查看次数: 3909
发表评论
登录后再发表评论!