コード例 #1
0
        private void Decrypt()
        {
            string cipherText = GetRichTextBoxText(CipherRTB).ToLower();

            if (cipherText == "")
            {
                PlainTextRTB.IsEnabled = false;
                return;
            }

            PlainTextRTB.IsEnabled = true;

            string decryptedText = Decrypt(Convert.ToInt32(KeySlider.Value), cipherText);

            PlainTextRTB.Document.Blocks.Clear();
            PlainTextRTB.AppendText(decryptedText);
        }
コード例 #2
0
        private void CipherRTB_TextChanged(object sender, TextChangedEventArgs e)
        {
            string cipherText = GetRichTextBoxText(CipherRTB).ToLower();

            if (cipherText == "")
            {
                PlainTextRTB.IsEnabled = false;
                return;
            }

            PlainTextRTB.IsEnabled = true;

            string decryptedText = Decrypt(cipherText);

            PlainTextRTB.Document.Blocks.Clear();
            PlainTextRTB.AppendText(decryptedText);

            UpdateSingleFrequenciesTable();
            UpdatePairFrequenciesTable();
        }
コード例 #3
0
        private void Switch()
        {
            string str = GetRichTextBoxText(CipherRTB).ToLower();

            PlainTextRTB.IsEnabled = true;
            string temp = "";

            foreach (char c in str)
            {
                if (c == 'q')
                {
                    temp += "h";
                }
                else if (c == 'm')
                {
                    temp += "t";
                }
                else if (c == 's')
                {
                    temp += "e";
                }
                else if (c == 'u')
                {
                    temp += "r";
                }
                else if (c == 'k')
                {
                    temp += "a";
                }
                else if (c == 'v')
                {
                    temp += "n";
                }
                else if (c == 'h')
                {
                    temp += "u";
                }
                else if (c == 't')
                {
                    temp += "m";
                }
                else if (c == 'd')
                {
                    temp += "b";
                }
                else if (c == 'b')
                {
                    temp += "o";
                }
                else if (c == 'j')
                {
                    temp += "f";
                }
                else if (c == 'n')
                {
                    temp += "d";
                }
                else if (c == 'x')
                {
                    temp += "i";
                }
                else if (c == 's')
                {
                    temp += "e";
                }
                else if (c == 'p')
                {
                    temp += "c";
                }
                else if (c == 'e')
                {
                    temp += "s";
                }
                else if (c == 'a')
                {
                    temp += "y";
                }
                else if (c == 'y')
                {
                    temp += "p";
                }
                else if (c == 'w')
                {
                    temp += "g";
                }
                else if (c == 'g')
                {
                    temp += "v";
                }
                else if (c == 'i')
                {
                    temp += "x";
                }
                else if (c == 'f')
                {
                    temp += "k";
                }
                else if (c == 'c')
                {
                    temp += "j";
                }
                else if (c == 'r')
                {
                    temp += "q";
                }
                else if (c == 'o')
                {
                    temp += "w";
                }
                else
                {
                    temp += c;
                }
            }

            PlainTextRTB.Document.Blocks.Clear();
            PlainTextRTB.AppendText(temp);
            //PlainTextRTB.Document.Blocks.Clear();
            //PlainTextRTB.AppendText("izrxgrtnwzqf".ToUpper());
        }
コード例 #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            if (!(sender is Button))
            {
                return;
            }

            Button button = sender as Button;

            if (SourceButton == null)
            {
                SourceButton            = button;
                SourceButton.Background = Brushes.Green;
            }
            else if (DestinationButton == null)
            {
                DestinationButton = button;
                if (DestinationButton == SourceButton)
                {
                    char ch1 = SourceButton.Content.ToString().ToLower()[0];
                    char ch2 = AlphabetDictionary[ch1];
                    SwapChars(ch1, ch1);
                    SwapChars(ch2, ch2);
                    SourceButton.Background = Brushes.LightGray;
                    DestinationButton       = FindButton(ch2.ToString().ToUpper());
                    if (DestinationButton != null)
                    {
                        DestinationButton.Background = Brushes.LightGray;
                    }
                }
                else
                {
                    char source      = SourceButton.Content.ToString().ToLower()[0];
                    char destination = DestinationButton.Content.ToString().ToLower()[0];
                    SwapChars(source, destination);
                }

                string decryptedText = Decrypt(GetRichTextBoxText(CipherRTB));
                string plaintText    = GetRichTextBoxText(PlainTextRTB);
                if (plaintText != "" && plaintText != null)
                {
                    PlainTextRTB.Document.Blocks.Clear();
                    PlainTextRTB.AppendText(decryptedText);
                }

                NewAlphabet.Text = "";
                char c = 'a';
                foreach (var ele in AlphabetDictionary)
                {
                    NewAlphabet.Text += AlphabetDictionary[c].ToString().ToUpper() + " ";
                    c = (char)(c + 1);
                }

                SourceButton      = null;
                DestinationButton = null;
            }
        }