예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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!");
        }
예제 #7
0
 public void FailWithShortMessage()
 {
     Assert.Throws <ArgumentException>(() => Substitution.Encode("12345678901234567890123456789", "message", SBlockTypes.GOST));
 }
예제 #8
0
 public void FailWithShortKey()
 {
     Assert.Throws <ArgumentException>(() => Substitution.Encode("12345678901234567890123456789", "1234567887654321", SBlockTypes.GOST));
 }