コード例 #1
0
        public void DecryptWithNullTest()
        {
            const string ciphertext = "abbaba";

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

            cipher.Decrypt(ciphertext, null);
        }
コード例 #2
0
        public void DecryptNullTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

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

            cipher.Decrypt(null, key);
        }
コード例 #3
0
        public void DecryptWrongKeyTest3()
        {
            var key = new SimpleSubstitutionKey(("abcd", "badc"));

            const string ciphertext = "aacabc";

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

            cipher.Decrypt(ciphertext, key);
        }
コード例 #4
0
        public void DecryptTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            const string plaintext  = "abbaba";
            const string ciphertext = "baabab";

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

            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, key));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public void DecryptWrongTextTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            const string ciphertext = "aacabc";

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

            Assert.AreEqual("bbcbac", cipher.Decrypt(ciphertext, key));
        }
コード例 #7
0
        public void DecryptWrongTextStrictTest()
        {
            var key = new SimpleSubstitutionKey(("ab", "ba"));

            const string ciphertext = "aacabc";

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

            cipher.Decrypt(ciphertext, key);
        }
コード例 #8
0
ファイル: CipherManager.cs プロジェクト: PcloD/TEDCore
        public string Decrypt(string cipherText)
        {
            string plainText = cipherText;

            SimpleSubstitutionCipher simpleSubstitutionCipher = new SimpleSubstitutionCipher();

            simpleSubstitutionCipher.SetKey(SIMPLE_SUBSTITUTION_CIPHER_KEY);
            plainText = simpleSubstitutionCipher.Decrypt(plainText);

            AffineCipher affineCipher = new AffineCipher();

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

            CaesarCipher caesarCipher = new CaesarCipher();

            caesarCipher.SetKey(CAESAR_CIPHER_KEY);
            plainText = caesarCipher.Decrypt(plainText);

            return(plainText);
        }