コード例 #1
0
        /// <summary>
        /// Encodes user inputted text using the generated cipher
        /// </summary>
        ///
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        /// <author>
        /// Ian Cordova - 9:30pm, 4/23/2018
        /// </author>
        private void btnTranslate_Click(object sender, RoutedEventArgs e)
        {
            string plainText;
            string cipherText;

            // If the user has not generated a cipher yet, print this error message.
            string errorMessage = "Please generate a cipher to translate your text first.";

            if (m_currentCipher.Count == 0)
            {
                rebCipherText.IsReadOnly = false;
                rebCipherText.Document.SetText(Windows.UI.Text.TextSetOptions.None, errorMessage);
                rebCipherText.IsReadOnly = true;
                return;
            }

            // Get text from rich edit box and save to plainText string
            rebPlainText.Document.GetText(Windows.UI.Text.TextGetOptions.None, out plainText);

            // Encode plain text with the generated cipher
            cipherText = CipherMaker.EncodeText(plainText, m_currentCipher);

            // Set cipher text to rich edit box
            rebCipherText.IsReadOnly = false;
            rebCipherText.Document.SetText(Windows.UI.Text.TextSetOptions.None, cipherText);
            rebCipherText.IsReadOnly = true;
        }
コード例 #2
0
        /// <summary>
        /// Generates a cipher for the user
        /// </summary>
        ///
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        /// <author>
        /// Ian Cordova - 4:55pm, 4/23/2018
        /// </author>
        private void createCipherBtn_Click(object sender, RoutedEventArgs e)
        {
            // Clears textbox before new generation
            tbCipherAlphabet.Text = "";

            Dictionary <char, char> cipher = new Dictionary <char, char>();

            cipher = CipherMaker.CreateSubCipher();

            // Adds each value from cipher to text box to be displayed
            foreach (KeyValuePair <char, char> entry in cipher)
            {
                tbCipherAlphabet.Text += entry.Value.ToString();
                tbCipherAlphabet.Text += "\n";
            }

            m_currentCipher = cipher;
        }