木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2009-05-25 👁 4502 👍 0 💬 0 🔄 来源:本站原创
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)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 使用7-Zip获取QQ2009已安装的表情图片 下一篇 → 一段显示下载进度条的下载文件代码