2011年8月25日 星期四

[.NET] C# 常用加密演算法整理(三) 移位 加密/解密





字串位移加密

    public static string ShiftEncrypt(string Input)
    {
        try
        {
            string _temp = "";
            int _inttemp;
            char[] _chartemp = Input.ToCharArray();
            for (int i = 0; i < _chartemp.Length; i++)
            {
                _inttemp = _chartemp[i] + 1;
                _chartemp[i] = (char)_inttemp;
                _temp += _chartemp[i];
            }
            return _temp;
        }
        catch
        {
            return Input.ToString();
        }
    }



字串位移解密

    public static string ShiftDecrypt(string Input)
    {
        try
        {
            string _temp = "";
            int _inttemp;
            char[] _chartemp = Input.ToCharArray();
            for (int i = 0; i < _chartemp.Length; i++)
            {
                _inttemp = _chartemp[i] - 1;
                _chartemp[i] = (char)_inttemp;
                _temp += _chartemp[i];
            }
            return _temp;
        }
        catch
        {
            return Input.ToString();
        }
    }

沒有留言:

張貼留言