コード例 #1
0
        public string Decipher(string message, int key)
        {
            Dictionary <char, string> tabulaRecta = TableFunctions.MakeTable(charLine);
            string output = "";

            message = message.ToUpper();
            message = String.Concat(message.Where(c => !Char.IsWhiteSpace(c)));

            try
            {
                while (output.Length < message.Length)
                {
                    for (int i = 0; i < message.Length; i++)
                    {
                        int    charPos = TableFunctions.GetCharPos(message[i], charLine[key]);
                        string temp    = tabulaRecta['A'];
                        output += temp[charPos];
                    }
                }
            }
            catch (Exception e)
            {
                MultiCipherCLI.InvalidChar();
            }
            return(output);
        }
コード例 #2
0
        public string Encipher(string message, int key)
        {
            Dictionary <char, string> tabulaRecta = TableFunctions.MakeTable(charLine);
            string output = "";

            message = message.ToUpper();
            message = String.Concat(message.Where(c => !Char.IsWhiteSpace(c)));


            try
            {
                while (output.Length < message.Length)
                {
                    for (int i = 0; i < message.Length; i++)
                    {
                        foreach (KeyValuePair <char, string> charX in tabulaRecta)
                        {
                            if (charLine[key] == charX.Key)
                            {
                                int charPos = TableFunctions.GetCharPos(message[i], 'A');
                                output += charX.Value[charPos];
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MultiCipherCLI.InvalidChar();
            }
            return(output);
        }