Esempio n. 1
0
        public void StandartDesTest()
        {
            bool   result   = true;
            string inFile   = @"C:\Users\aleks\Desktop\test rpks\test2.txt";
            string out1File = @"C:\Users\aleks\Desktop\test rpks\62.txt";
            string out2File = @"C:\Users\aleks\Desktop\test rpks\63.txt";

            int         k  = 0;
            StandartDes sd = new StandartDes(ref k, null, null);

            sd.EncryptNoProgressDisplay(inFile, out1File);
            sd.DecipherNoProgressDisplay(out1File, out2File);
            try
            {
                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;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                result = false;
            }
            File.Delete(out1File);
            File.Delete(out2File);
            Assert.IsTrue(result);
        }
Esempio n. 2
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);
        }