public void FailWithEmptyData() { byte[] key = Encoding.UTF8.GetBytes("12345678901234567890123456789012"); byte[] message = Encoding.UTF8.GetBytes("1234567887654321"); Assert.Throws <ArgumentException>(() => Substitution.Encode(new byte[] { }, message, SBlockTypes.GOST)); Assert.Throws <ArgumentException>(() => Substitution.Encode(key, new byte[] { }, SBlockTypes.GOST)); Assert.Throws <ArgumentException>(() => Substitution.Encode(new byte[] { }, new byte[] { }, SBlockTypes.GOST)); }
public void FailWithNullData() { byte[] key = Encoding.UTF8.GetBytes("12345678901234567890123456789012"); byte[] message = Encoding.UTF8.GetBytes("1234567887654321"); Assert.Throws <ArgumentNullException>(() => Substitution.Encode(null, message, SBlockTypes.GOST)); Assert.Throws <ArgumentNullException>(() => Substitution.Encode(key, null, SBlockTypes.GOST)); Assert.Throws <ArgumentNullException>(() => Substitution.Encode((byte[])null, null, SBlockTypes.GOST)); }
public void FailWithNotEqualsSBlocks() { var encoded = Substitution.Encode("12345678901234567890123456789012", "1234567887654321", SBlockTypes.CryptoProB); var decoded = Substitution.Decode("12345678901234567890123456789012", "1234567887654321", SBlockTypes.GOST); Assert.IsNotNull(encoded); Assert.IsNotNull(decoded); Assert.IsNotEmpty(encoded); Assert.IsNotEmpty(decoded); Assert.AreNotEqual(decoded, encoded); }
public void PassWithStrings() { var encoded = Substitution.Encode("12345678901234567890123456789012", "1234567887654321", SBlockTypes.GOST); var decoded = Substitution.Decode("12345678901234567890123456789012", "1234567887654321", SBlockTypes.GOST); Assert.IsNotNull(encoded); Assert.IsNotNull(decoded); Assert.IsNotEmpty(encoded); Assert.IsNotEmpty(decoded); Assert.AreEqual(decoded, encoded); }
public void PassWithBytes() { byte[] key = Encoding.UTF8.GetBytes("12345678901234567890123456789012"); byte[] message = Encoding.Default.GetBytes("1234567887654321"); var encoded = Substitution.Encode(key, message, SBlockTypes.GOST); var decoded = Substitution.Decode(key, message, SBlockTypes.GOST); Assert.IsNotNull(encoded); Assert.IsNotNull(decoded); Assert.IsNotEmpty(encoded); Assert.IsNotEmpty(decoded); Assert.AreEqual(decoded, encoded); }
public ActionResult <string> GetEncrypt(string method, string str, string key) { try { if (method == "caesar") { Caesar caesar = new Caesar(); var result = caesar.Encode(str, key); if (result.Item2 == true) { SaveEncryptItems(method, str, key, result.Item1); return(result.Item1); } } else if (method == "railfence") { RailFence railFence = new RailFence(); var result = railFence.Encode(str, key); if (result.Item2 == true) { SaveEncryptItems(method, str, key, result.Item1); return(result.Item1); } } else if (method == "affine") { Affine affine = new Affine(); var result = affine.Encode(str, key); if (result.Item2 == true) { SaveEncryptItems(method, str, key, result.Item1); return(result.Item1); } } else if (method == "substitution") { Substitution substitution = new Substitution(); var result = substitution.Encode(str, key); if (result.Item2 == true) { SaveEncryptItems(method, str, key, result.Item1); return(result.Item1); } } } catch (System.Exception e) { return(e.Message); } return("No such method!"); }
public void FailWithShortMessage() { Assert.Throws <ArgumentException>(() => Substitution.Encode("12345678901234567890123456789", "message", SBlockTypes.GOST)); }
public void FailWithShortKey() { Assert.Throws <ArgumentException>(() => Substitution.Encode("12345678901234567890123456789", "1234567887654321", SBlockTypes.GOST)); }