예제 #1
0
        private string TestSpeed(string inFile)
        {
            string result;

            string out1File = @"C:\Users\aleks\Desktop\test rpks\1.txt";
            string out2File = @"C:\Users\aleks\Desktop\test rpks\2.txt";
            int    k        = 0;
            long   length   = new System.IO.FileInfo(inFile).Length;

            result = "Size of file " + length + "\n";
            StandartDes sd = new StandartDes(ref k, null, null);
            MyDes       md = new MyDes(ref k, null, null);



            System.Diagnostics.Stopwatch sw2 = new Stopwatch();
            sw2.Start();
            md.EncryptNoProgressDisplay(inFile, out1File);

            sw2.Stop();
            result += "My desE=       " + (sw2.ElapsedMilliseconds / 100.0).ToString() + "\n";

            System.Diagnostics.Stopwatch sw3 = new Stopwatch();
            sw3.Start();

            md.DecipherNoProgressDisplay(out1File, out2File);
            sw3.Stop();
            result += "My desD=       " + (sw3.ElapsedMilliseconds / 100.0).ToString() + "\n";
            File.Delete(out1File);
            File.Delete(out2File);

            System.Diagnostics.Stopwatch sw1 = new Stopwatch();
            sw1.Start();
            sd.EncryptNoProgressDisplay(inFile, out1File);
            sd.DecipherNoProgressDisplay(out1File, out2File);
            sw1.Stop();
            result += "Standart des= " + (sw1.ElapsedMilliseconds / 100.0).ToString() + "\n";


            File.Delete(out1File);
            File.Delete(out2File);
            return(result);
        }
예제 #2
0
        public void MyImplementationDesTest()
        {
            bool   result   = true;
            string inFile   = @"C:\Users\aleks\Desktop\test rpks\12.png";
            string out1File = @"C:\Users\aleks\Desktop\test rpks\12test1.png";
            string out2File = @"C:\Users\aleks\Desktop\test rpks\12test2.png";
            int    k        = 0;
            MyDes  md       = new MyDes(ref k, null, null);

            md.EncryptNoProgressDisplay(inFile, out1File);
            md.DecipherNoProgressDisplay(out1File, out2File);

            using (FileStream fsread1 = new FileStream(inFile, FileMode.Open, FileAccess.Read))
            {
                using (FileStream fsread2 = new FileStream(out2File, FileMode.Open, FileAccess.Read))
                {
                    if (fsread1.Length != fsread2.Length)
                    {
                        throw new Exception(fsread1.Length + " " + fsread2.Length);
                        result = false;
                    }
                    else
                    {
                        for (int i = 0; i < fsread1.Length; i++)
                        {
                            if (fsread1.ReadByte() != fsread2.ReadByte())
                            {
                                result = false;
                                break;
                            }
                        }
                    }
                }
            }


            File.Delete(out1File);
            File.Delete(out2File);
            Assert.IsTrue(result);
        }