Exemplo n.º 1
0
        public void GetDec_Test()
        {
            var sDes = new SDesAlgorithm();
            var actualResult = new List<byte> { 0, 1, 1, 1, 0, 1, 0, 0 };

            CollectionAssert.AreEqual(actualResult, sDes.StringToBytes("t").ToList());
        }
Exemplo n.º 2
0
 public void DecToBin()
 {
     var sDes = new SDesAlgorithm();
     var bytes = sDes.DecToBytes(642);
     var actualResult = new List<byte> { 1, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
     CollectionAssert.AreEqual(actualResult, bytes.ToList());
 }
Exemplo n.º 3
0
        private static string EncriptText(SDesAlgorithm sDes, string text, IList<byte> k1, IList<byte> k2)
        {
            var str = string.Empty;
            for (var i = 0; i < text.Count(); i++)
            {
                var o = sDes.Encript(text[i].ToString());
                str += o;

            //                IList<byte> bytes = sDes.StringToBytes(text[i].ToString());
            //              //  Console.WriteLine("Symbol: '{0}' to bytes: {1}", text[i], string.Join("", bytes));
            //
            //                var ip = sDes.ToIP(bytes);
            //                Print("IP: {0}", ip);
            //
            //                var fk1 = sDes.Fk(ip, k1);
            //                Print("Fk: {0}", fk1);
            //
            //                var sw = sDes.SW(fk1, ip.Skip(4).Take(4).ToList());
            //                Print("SW: {0}", sw);
            //
            //                var fk2 = sDes.Fk(sw, k2);
            //                Print("Fk: {0}", fk2);
            //
            //                var sw2 = sDes.SW(fk1, fk2);
            //                Print("SW: {0}", sw2);
            //
            //                var ip_1 = sDes.ToIP_1(sw2);
            //                Print("IP-1 {0}", ip_1);

               //     Console.WriteLine("Encrypt symbol: {0}", o);
            }
            return str;
        }
Exemplo n.º 4
0
 public void CyclicShift_Two_Test()
 {
     var sDes = new SDesAlgorithm();
     var butes = new List<byte> { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 };
     var actualResult = new List<byte> { 0, 0, 1, 0, 0, 0, 0, 0, 1, 1 };
     CollectionAssert.AreEqual(actualResult, sDes.CyclicShift_Two(butes).ToList());
 }
Exemplo n.º 5
0
 public void Fk()
 {
     var sDes = new SDesAlgorithm();
     var param1 = new List<byte> { 1, 1, 1, 0, 1, 0, 0, 0 };
     var param2 = new List<byte> { 1, 0, 1, 0, 0, 1, 0, 0 };
     var actualResult = new List<byte> {0, 0, 1, 1 };
     CollectionAssert.AreEqual(actualResult, sDes.Fk(param1, param2).ToList());
 }
Exemplo n.º 6
0
 public void GetEnc_Test()
 {
     var sDes = new SDesAlgorithm();
     var actualResult = new List<byte> { 0, 1, 1, 1, 0, 1, 0, 0 };
     var stringBin = string.Join(string.Empty, actualResult);
     var dec = Convert.ToInt32(stringBin, 2);
     var text = char.ConvertFromUtf32(dec);
     CollectionAssert.AreEqual(actualResult, sDes.StringToBytes("t").ToList());
     Assert.AreEqual(text, "t");
 }
Exemplo n.º 7
0
        public void GenerateKeys_Test()
        {
            var sDes = new SDesAlgorithm();
            sDes.GenerateKeys(642);

            var actualK1 = new List<byte> { 1, 0, 1, 0, 0, 1, 0, 0 };
            var actualK2 = new List<byte> { 0, 1, 0, 0, 0, 0, 1, 1 };
            CollectionAssert.AreEqual(actualK1, sDes.k1.ToList());
            CollectionAssert.AreEqual(actualK2, sDes.k2.ToList());
        }
Exemplo n.º 8
0
        private static void GenerateKeys(int key, SDesAlgorithm sDes, out IList<byte> k1, out IList<byte> k2)
        {
            sDes.GenerateKeys(key);
            var bytes = sDes.DecToBytes(key);

            bytes = sDes.ToP10(bytes);
            Print("P10: {0}", bytes);

            bytes = sDes.CyclicShift_One(bytes);
            Print("Cyclin shift 1: {0}", bytes);

            k1 = sDes.ToP8(bytes);
            Print("K1: {0}", k1);

            bytes = sDes.CyclicShift_Two(bytes);
            Print("Cyclin shift {0}", bytes);

            k2 = sDes.ToP8(bytes);
            Print("K2: {0}", k2);
        }
Exemplo n.º 9
0
 public void IncorrectValues()
 {
     var sDes = new SDesAlgorithm();
     sDes.DecToBytes(1024);
     sDes.DecToBytes(-1);
 }
Exemplo n.º 10
0
 public void EP()
 {
     var sDes = new SDesAlgorithm();
     var actualResult = new List<byte> { 0, 1, 0, 0, 0, 0, 0, 1 };
     CollectionAssert.AreEqual(actualResult, sDes.EP(new List<byte> { 1, 0, 0, 0 }).ToList());
 }
Exemplo n.º 11
0
 public void SMatrix()
 {
     var sDes = new SDesAlgorithm();
     var param1 = new List<byte> { 1, 1, 1, 0, 0, 1, 0, 1 };
     var actualResult = new List<byte> { 1, 1, 0, 1 };
     CollectionAssert.AreEqual(actualResult, sDes.SMatrix(param1).ToList());
 }
Exemplo n.º 12
0
 public void P8_Test2()
 {
     var sDes = new SDesAlgorithm();
     var butes = new List<byte> { 0, 0, 1, 0, 0, 0, 0, 0, 1, 1 };
     var actualResult = new List<byte> { 0, 1, 0, 0, 0, 0, 1, 1 };
     CollectionAssert.AreEqual(actualResult, sDes.ToP8(butes).ToList());
 }
Exemplo n.º 13
0
        public void MainTest()
        {
            var sDes = new SDesAlgorithm();
            sDes.GenerateKeys(642);

            var text = "t";

            var encrpt = sDes.Encript(text);
            var decr = sDes.Decript(encrpt);
            Assert.AreEqual(text, decr);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Key:");
            int key = int.Parse(s: Console.ReadLine());

            SDesAlgorithm sDes = new SDesAlgorithm();

            IList<byte> k1;
            IList<byte> k2;
            GenerateKeys(key, sDes, out k1, out k2);

            Console.WriteLine("");
            Console.WriteLine("Enter text:");
            string text = Console.ReadLine();

            var o = EncriptText(sDes, text, k1, k2);

             //   DecriptText(sDes, o, k1, k2);

            Console.ReadKey();
        }