自己写的加密方式

const string sNil = "'(&.&!'%&$\"'&)\" \",&)$(%#$-$#$$\" ";    //'''(&.&!''%&$"''&)" ",&)$(%#$-$#$$" ' ;
        const string sTemp = " !\"#$%&'()*+,-./";                      // ' !"#$%&''()*+,-./';
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xUserID"></param>
        /// <returns></returns>
        public static string EncodeUserID(string xUserID)
        {
            char[] sUserID = xUserID.ToCharArray();
            string sResult = sNil.Substring((sUserID.Length - 1) * 2, 30 - (sUserID.Length - 1) * 2);   //DS-〉&.&!'%&$\"'&)\" \",&)$(%#$-
            int k = 0, j = 0, l = 0;
            for (int i = sUserID.Length - 1; i >= 0; i--)
            {
                l = Convert.ToInt32(sUserID[i]);
                k = (l - 32) % 16;
                j = ((l - 32) / 16) + 1;

                sResult = sResult + Convert.ToChar(32 + j + 1) + sTemp[k];
            }
            return sResult;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xUserID"></param>
        /// <returns></returns>
        public static string DecodeUserID(string xUserID)
        {
            string resultStr = string.Empty, sResult = string.Empty;
            for (var i = xUserID.Length - 1; i >= 0; )
            {
                int x = sTemp.IndexOf(xUserID[i]);
                int y = Convert.ToInt32(xUserID[i - 1]) - 33;
                int l = ((y - 1) * 16) + 32 + x;
                resultStr += Convert.ToChar(l);
                sResult = sNil.Substring((resultStr.Length - 1) * 2, 30 - (resultStr.Length - 1) * 2);
                string tmpStr = xUserID.Substring(0, i - 1);
                if (sResult == tmpStr)
                {
                    break;
                }
                i -= 2;
            }
            return resultStr;
        } 

  

posted @ 2014-07-31 11:26  kingkoo  阅读(1008)  评论(0编辑  收藏  举报