public void Bifid()
        {
            BifidCipher cipher = new BifidCipher();

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

            const string plaintext  = "FLEEATONCE";
            const string ciphertext = "UAEOLWRINS";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, key), true);
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, key), true);
        }
Example #2
0
        /*
         * Instantiates different ciphers based on the stack of used ciphers.
         */
        private bool LoadCiphers()
        {
            int i = 0;

            try
            {
                foreach (ListBoxItem currentItem in usedCiphers.Items)
                {
                    if (textBoxes[i].Text.Equals(""))
                    {
                        errorsTextBox.Text = "You must introduce a key for each cipher!";
                        return(false);
                    }
                    switch (currentItem.Content)
                    {
                    case "Caesar":
                        ciphers[i] = new CaesarCipher();
                        break;

                    case "Nihilist":
                        ciphers[i] = new NihilistCipher();
                        break;

                    case "Bifid":
                        ciphers[i] = new BifidCipher();
                        break;

                    case "Playfair":
                        ciphers[i] = new PlayfairCipher();
                        break;
                    }
                    ciphers[i].SetKey(textBoxes[i].Text);
                    textBoxes[i].Text = ciphers[i].GetKeyValue();
                    i++;
                }
            }
            catch (InvalidKeyFormatException ex)
            {
                errorsTextBox.Text = ex.Message;
                return(false);
            }

            return(true);
        }