C#Caesar Shift解密在多次轮班和轮班变长后停止显示轮班

时间:2015-12-15 16:26:50

标签: c# encryption caesar-cipher

我正在开发一个Ceaser Cipher,用于解密附加的.TXT文件。它必须在解密的文本中显示所有可能的移位和结果。但到目前为止,我所得到的只是8个班次,每个班次越来越长,更多的文字并不意味着发生。有人可以帮我识别下面代码中的问题吗?

public class Program
{
    public static void Main(string[] args)
    {
        string text = System.IO.File.ReadAllText(@"FilePath");
        string file;
        int shift = 0;
        string decoded_text;

        char character = '0';

        char[] alphabet = new char[26]
        {
        'A','B','C','D',
        'E','F','G','H',
        'I','J','K','L',
        'M','N','O','P',
        'Q','R','S','T',
        'U','V','W','X',
        'Y', 'Z'
         };

        Console.WriteLine("The encrypted text is \n{0}", text); //Displays the encrypted text, shows that it gathered the text correctly from the fiile

        for (int i = 0; i < alphabet.Length; i++)
        {
            decoded_text = "";
            foreach (char c in text)
            {
                character = c;

                if (!alphabet.Contains(character))
                {
                    decoded_text += character;
                    continue;
                }

                shift = Array.IndexOf(alphabet, character) - i;
                if (shift <= 0) shift = shift + 26;

                if (shift >= 26) shift = shift - 26;

                text += alphabet[shift];
            }
            Console.WriteLine("\nShift {0} \n {1}", i + 1, text);
        }
    }
}

这是.TXT文件中包含的文字:

  

YMJNS HWJIN GQJQJ LFHDT   KYMJR FYMJR FYNHF QLJSN   ZXLJT WLJGT TQJBN QQGJJ   CUQTW JINSF KWJJU ZGQNH   YFQPN SMNXM TRJHN YDTKQ   NSHTQ STSYM JGNHJ SYJSF   WDTKM NXGNW YMXYT UGTTQ   JBFXG TWSTS YMJXJ HTSIT   KSTAJ RGJWJ NLMYJ JSKNK   YJJSN SYTRT IJXYK FRNQD   HNWHZ RXYFS HJXYM JXTST   KFXMT JRFPJ WXYTU QFWLJ   QDXJQ KYFZL MYMJB JSYTS   YTGJH TRJTS JTKYM JBTWQ   我是SJXYR FYMJR FYNHN   FSXBM TXJBT WPSTB KTWRX   YMJGF XNXTK HTRUZ YJWXH   NJSHJ FSIJQ JHYWT SNHHN   WHZNY WDXYT UMJQF NIYMJ   KTZSI FYNTS XTKYM JINLN   YFQJW FFSIN XBNIJ QDWJH   TLSNX JIFXY MJKTW JKFYM   JWTKY MJINL NYFQF LJXYT   UGTTQ JFSFQ LJGWF NXSTB   FKZSI FRJSY FQFXU JHYTK   RTIJW SRFYM JRFYN HXFSI   TAJWY MJQFX YHJSY ZWDBF   XZXJI YTKTW RYMJY MJTWJ   YNHFQ KTZSI FYNTS TKRTI   JWSHT RUZYJ WXHNJ SHJJS   我

0 个答案:

没有答案