public void EncryptWithNullTest()
        {
            const string plaintext = "abbaba";

            var cipher = new SimpleSubstitutionCipher(new Alphabet("ab"));

            cipher.Encrypt(plaintext, null);
        }
        public void EncryptNullTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            var cipher = new SimpleSubstitutionCipher(new Alphabet("ab"));

            cipher.Encrypt(null, key);
        }
        public void EncryptWrongKeyTest1()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            const string plaintext = "aacabc";

            var cipher = new SimpleSubstitutionCipher(new Alphabet("abc"));

            cipher.Encrypt(plaintext, key);
        }
        public void EncryptTest()
        {
            var          key        = new SimpleSubstitutionKey(("ab", "ba"));
            const string plaintext  = "abbaba";
            const string ciphertext = "baabab";

            var cipher = new SimpleSubstitutionCipher(new Alphabet("ab"));

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, key));
        }
        public void AbsorbtionTest()
        {
            var          encKey    = new SimpleSubstitutionKey(("abc", "bca"));
            var          decKey    = KeyGenerator.GetSimpleSubstitutionDecryptionKey(encKey);
            const string plaintext = "abcbabca";

            var cipher = new SimpleSubstitutionCipher(new Alphabet("abc"));

            Assert.AreEqual(
                plaintext,
                cipher.Decrypt(cipher.Encrypt(plaintext, encKey), decKey));
        }
        public void EncryptWrongTextTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            const string plaintext = "aacabc";

            var cipher = new SimpleSubstitutionCipher(new Alphabet("ab"))
            {
                IsStrict = false
            };

            Assert.AreEqual("bbcbac", cipher.Encrypt(plaintext, key));
        }
Ejemplo n.º 7
0
        public string Encrypt(string plainText)
        {
            string cipherText = plainText;

            CaesarCipher caesarCipher = new CaesarCipher();

            caesarCipher.SetKey(CAESAR_CIPHER_KEY);
            cipherText = caesarCipher.Encrypt(cipherText);

            AffineCipher affineCipher = new AffineCipher();

            affineCipher.SetKeys(new int[] { AFFINE_CIPHER_KEY_A, AFFINE_CIPHER_KEY_B });
            cipherText = affineCipher.Encrypt(cipherText);

            SimpleSubstitutionCipher simpleSubstitutionCipher = new SimpleSubstitutionCipher();

            simpleSubstitutionCipher.SetKey(SIMPLE_SUBSTITUTION_CIPHER_KEY);
            cipherText = simpleSubstitutionCipher.Encrypt(cipherText);

            return(cipherText);
        }