public void Hill_CipherTest() { string msg = "HELLOWORLD"; Cipher cipher = new Hill_Cipher(msg, "CDFH"); Assert.IsNotNull(cipher); cipher = null; Assert.IsNull(cipher); cipher = new Hill_Cipher(msg, "CDFH"); Assert.IsNotNull(cipher); // Check conversion with 2x2 matrix cipher.Message = cipher.Encrypt(); string actual = cipher.Decrypt(); Assert.AreEqual(msg, actual, true); cipher.Message = "Hello World I am William"; string expected = "HELLOWORLDIAMWILLIAM"; cipher.Message = cipher.Encrypt(); Console.WriteLine(cipher.Message); actual = cipher.Decrypt(); Assert.AreEqual(expected, actual, true); // Check conversion with 3x3 matrix /*msg = "Hello Will the hill cipher now works!"; * cipher = new Hill_Cipher(msg, "BAAABAAAB"); * cipher.Message = cipher.Encrypt(); * string actual = cipher.Decrypt(); * expected = "hellowillthehillciphernowworks"; * Assert.AreEqual(expected, actual, true);*/ }
public void Is_Key_ValidTest() { // 2x2 Matrix Cipher cipher = new Hill_Cipher("DCODEZ", "CDFH"); Assert.IsTrue(cipher.Is_Key_Valid()); // 3x3 Matrix /*cipher = new Hill_Cipher("DCODEZ", "GYBNQKURP"); * Assert.IsTrue(cipher.Is_Key_Valid());*/ // False cipher = new Hill_Cipher("DCODEZ", "ACDFHWDE"); Assert.IsFalse(cipher.Is_Key_Valid()); // Checks after runnning encryption try { cipher = new Hill_Cipher("DCODEZ", "ABCD"); cipher.Encrypt(); Assert.Fail(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
public void EncryptTest() { // Testing 2x2 matrix Cipher cipher = new Hill_Cipher("DCODEZ", "CDFH"); string expected = cipher.Encrypt(); string actual = "MDLNFN"; Assert.AreEqual(expected, actual); // Testing 3x3 matrix /*cipher = new Hill_Cipher("ACT", "GYBNQKURP"); * actual = cipher.Encrypt(); * expected = "POH"; * Assert.AreEqual(expected, actual);*/ }