Exemplo n.º 1
0
        public void Rc4Test()
        {
            bool   result   = true;
            string inFile   = @"C:\Users\aleks\Desktop\test rpks\6.png";
            string out1File = @"C:\Users\aleks\Desktop\test rpks\6out1.png";
            string out2File = @"C:\Users\aleks\Desktop\test rpks\6out2.png";

            _encryptionAlgorithm.Rc4(inFile, out1File);
            _encryptionAlgorithm.Rc4(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)
                        {
                            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);
        }
Exemplo n.º 2
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            if (_selectedAction == SelectedAction.IsNotChosen)
            {
                IsRunning = true;
                OnPropertyChanged($"IsRunning");
                MessageBox.Show("Не выбран метод шифрования");
                Thread.Sleep(1);
                return;
            }

            if (_inputFileName.Length == 0 || _outputFileName.Length == 0)
            {
                IsRunning = true;
                OnPropertyChanged($"IsRunning");
                MessageBox.Show("Пути до файлов не заданы");
                Thread.Sleep(1);
                return;
            }


            CurrentProgress = 0;
            OnPropertyChanged($"CurrentProgress");
            string result = "";

            switch (_selectedAction)
            {
            case SelectedAction.IsMyEncryptionAlgorithm:
                result = _encryptionAlgorithm.MyAlgorithm(_inputFileName, _outputFileName, _modeEncryption);
                break;

            case SelectedAction.IsMyDes:
                result = _encryptionAlgorithm.MyImplementationDes(_inputFileName, _outputFileName, _modeEncryption);
                break;

            case SelectedAction.IsStandartDes:
                result = _encryptionAlgorithm.StandartDes(_inputFileName, _outputFileName, _modeEncryption);
                break;

            case SelectedAction.IsVernam:
                result = _encryptionAlgorithm.Vernam(_inputFileName, _outputFileName);
                break;

            case SelectedAction.IsRc4:
                result = _encryptionAlgorithm.Rc4(_inputFileName, _outputFileName);
                break;
            }



            if (result == "")
            {
                CurrentProgress = 100;
                Thread.Sleep(1);
                OnPropertyChanged($"CurrentProgress");
            }
            else
            {
                MessageBox.Show(result);
                CurrentProgress = -1;
                Thread.Sleep(1);
            }

            IsRunning = true;
            OnPropertyChanged($"IsRunning");
        }