Home ยป ASP.net | C# | DotNet

C# Sniplet Reverse Encryption

9. June 2010 by Administrator 0 Comments

Here is the simple encryption sniplet that i used.

You can used this sniplet in your projects.

 

        /// <summary>
        /// to use in encrypt
        /// Security.Reverse(datahere)
        /// ----
        /// to use in decrypt
        /// Security.Reverse(datahere)
        /// </summary>
        /// <param name="strValue"></param>
        /// <returns></returns>
        public static string Reverse(string strValue)
        {
            return genNewString(strValue);
        }

        private static string genNewString(string strValue)
        {
            int i, j, k;
            string strNewStringValue = "";
            char[] chrValue = strValue.ToCharArray();

            for (i = 0; i <= chrValue.Length - 1; i++)
            {
                // take the next character in the string
                j = (int)chrValue[i];

                // find out the character code
                k = (int)j;

                if (k >= 97 && k <= 109)
                {
                    // a ... m inclusive become n ... z
                    k = k + 13;
                }
                else if (k >= 110 && k <= 122)
                {
                    // n ... z inclusive become a ... m
                    k = k - 13;
                }
                else if (k >= 65 && k <= 77)
                {
                    // A ... m inclusive become n ... z
                    k = k + 13;
                }
                else if (k >= 78 && k <= 90)
                {
                    // N ... Z inclusive become A ... M
                    k = k - 13;
                }

                //add the current character to the string returned by the function
                strNewStringValue = strNewStringValue + (char)k;
            }

            return strNewStringValue;
        }

blog comments powered by Disqus