예제 #1
0
        public string MyAlgorithm(string inputFileName, string outputFileName, ModeEncryption mode)
        {
            _currentProgress = 0;
            try
            {
                using (FileStream fsread = new FileStream(inputFileName, FileMode.Open, FileAccess.Read))
                {
                    using (FileStream fswrite = new FileStream(outputFileName, FileMode.Create, FileAccess.Write))
                    {
                        Model2 part2 = new Model2();

                        var count = fsread.Length / 100;
                        if (count == 0)
                        {
                            throw new Exception("Пустой файл");
                        }
                        for (int i = 0; i < fsread.Length; i++)
                        {
                            if (_worker != null)
                            {
                                if (i % count == 0 && i != 0)
                                {
                                    _worker.ReportProgress(_currentProgress);
                                    Thread.Sleep(5);
                                    _currentProgress = _currentProgress + 1;
                                    _onPropertyChanged("CurrentProgress");
                                }
                            }

                            int  readByte = fsread.ReadByte();
                            uint res;
                            if (mode == ModeEncryption.Encrypt)
                            {
                                res = part2.SwapBits((uint)readByte, new List <byte> {
                                    5, 3, 7, 1, 4, 0, 6, 2
                                });
                            }
                            else
                            {
                                res = part2.SwapBits((uint)readByte, new List <byte> {
                                    5, 1, 7, 3, 6, 0, 4, 2
                                });
                            }
                            fswrite.WriteByte(BitConverter.GetBytes(res)[0]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return("");
        }
예제 #2
0
        public string StandartDes(string inputFileName, string outputFileName, ModeEncryption mode)
        {
            _currentProgress = 0;
            StandartDes sd = new StandartDes(ref _currentProgress,
                                             _worker, _onPropertyChanged);

            if (mode == ModeEncryption.Encrypt)
            {
                return(sd.Encrypt(inputFileName, outputFileName));
            }
            else
            {
                return(sd.Decipher(inputFileName, outputFileName));
            }
        }
예제 #3
0
        public string MyImplementationDes(string inputFileName, string outputFileName, ModeEncryption mode)
        {
            _currentProgress = 0;
            MyDes md = new MyDes(ref _currentProgress,
                                 _worker, _onPropertyChanged);

            if (mode == ModeEncryption.Encrypt)
            {
                return(md.Encrypt(inputFileName, outputFileName));
            }
            else
            {
                return(md.Decipher(inputFileName, outputFileName));
            }
        }