zoukankan      html  css  js  c++  java
  • C#中使用ROT13加密解密

        ROT13是一种简单的加密方式,主要是把26个英文字母前13个和后13个对调,起到一定的英文文字加密保护作用。 今天我们来看下在C#中使用ROT13加密解密的实现,我们就用一个实例来为大家解答一下吧.
        虽然加密方式简单,但是Windows的注册表里面都使用了ROT13加密,可见其使用还是比较多的。

    public string ROT13Encode(string InputText)
            {
                int i;
                char CurrentCharacter;
                int CurrentCharacterCode;
                string EncodedText = \"\";
                //Iterate through the length of the input parameter  
                for (i = 0; i < InputText.Length; i++)
                {
                    //Convert the current character to a char  
                    CurrentCharacter = System.Convert.ToChar(InputText.Substring(i, 1));
                    //Get the character code of the current character  
                    CurrentCharacterCode = (int)CurrentCharacter;
                    //Modify the character code of the character, - this  
                    //so that \"a\" becomes \"n\", \"z\" becomes \"m\", \"N\" becomes \"Y\" and so on  
                    if (CurrentCharacterCode >= 97 && CurrentCharacterCode <= 109)
                    {
                        CurrentCharacterCode = CurrentCharacterCode + 13; [Page]
                    }
                    else if (CurrentCharacterCode >= 110 && CurrentCharacterCode <= 122)
                    {
                        CurrentCharacterCode = CurrentCharacterCode - 13;
                    }
                    else if (CurrentCharacterCode >= 65 && CurrentCharacterCode <= 77)
                    {
                        CurrentCharacterCode = CurrentCharacterCode + 13;
                    }
                    else if (CurrentCharacterCode >= 78 && CurrentCharacterCode <= 90)
                    {
                        CurrentCharacterCode = CurrentCharacterCode - 13;
                    }
                    //Add the current character to the string to be returned   
                EncodedText = EncodedText + (char)CurrentCharacterCode;
                }
                return EncodedText;
            }

      [Page]
    加密和解密的方法都一样,把字符串传入方法返回得到的字符串就是要加密和解密的字符串了。
  • 相关阅读:
    Debugger and device times have drifted by more than 60s. Please correct this by running adb shell "date `date +%m%d%H%M%Y.%S`" on your debugger machine.
    react native 动画组件Animated
    react-navigation 报错解决方法
    Java并发编程:线程池的使用
    如何设置eclipse下查看java源码
    接口和抽象类
    java接口可以继承多个接口
    抽象类和抽象方法的区别
    final
    static
  • 原文地址:https://www.cnblogs.com/88223100/p/1302807.html
Copyright © 2011-2022 走看看