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 DecryptWrongKeyTest3() { var key = new SimpleSubstitutionKey(("abcd", "badc")); const string ciphertext = "aacabc"; var cipher = new SimpleSubstitutionCipher(new Alphabet("abc")); cipher.Decrypt(ciphertext, 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)); }
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); }
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); }
private void ExecuteSimpleSubstitutionSipher() { var cipher = new SimpleSubstitutionCipher(this.model.Alphabet) { IsStrict = this.model.IsStrict }; if (this.model.Action == "Зашифрувати") { this.Encrypt( cipher, new SimpleSubstitutionKey( (this.model.SSCFrom, this.model.SSCTo))); } else { this.Decrypt( cipher, KeyGenerator.GetSimpleSubstitutionDecryptionKey( new SimpleSubstitutionKey( (this.model.SSCFrom, this.model.SSCTo)))); } }