void CountTimerProgress(object obj) { ProgressStr massProcess = (ProgressStr)obj; massProcess.massProcess[1] = massProcess.openFileStream.Position; ProgressChange(massProcess.massProcess); }
void CountTimerProgress(object obj) //Метод для инициализации строки прогресса { ProgressStr massProcess = (ProgressStr)obj; massProcess.massProcess[1] = massProcess.openFileStream.Position; ProgressChange(massProcess.massProcess); }
public void CipherFile(string loadFilePath, string saveFileDial, int key) { if (initialState[1] == null) { getBitLFSR = GetBitLFSR1; } else { getBitLFSR = getGeffeBit; } FileStream saveFileStream = null; FileStream openFileStream = new FileStream(loadFilePath, FileMode.Open, FileAccess.Read, FileShare.None, 100000); BinaryReader reader = new BinaryReader(openFileStream); long length = new FileInfo(loadFilePath).Length; long[] massProcess = new long[3]; massProcess[0] = openFileStream.Length; string extension = Path.GetExtension(loadFilePath); if (key == 2 && extension == ".crypt") { string filePathDecrypt = loadFilePath.Remove(loadFilePath.Length - 6); extension = filePathDecrypt.Substring(filePathDecrypt.LastIndexOf(".")); saveFileStream = new FileStream(saveFileDial + extension, FileMode.Create, FileAccess.Write); } else { saveFileStream = new FileStream(saveFileDial + extension + ".crypt", FileMode.Create, FileAccess.Write); } ProgressStr prsttr = new ProgressStr { massProcess = massProcess, openFileStream = openFileStream }; TimerCallback tm = new TimerCallback(CountTimerProgress); System.Threading.Timer timerPr = new System.Threading.Timer(tm, prsttr, 0, 20); BinaryWriter readerSave = new BinaryWriter(saveFileStream); byte cipText = 0; byte origText; while (reader.BaseStream.Position != reader.BaseStream.Length) { origText = reader.ReadByte(); secOriginalByte(BinCOdeWithZeroFirst(Convert.ToString(origText, 2))); cipText = CipherByte(origText); secChiperByte(BinCOdeWithZeroFirst(Convert.ToString(cipText, 2))); readerSave.Write(cipText); } Thread.Sleep(21); timerPr.Dispose(); openFileStream.Close(); saveFileStream.Close(); }
public void CipherFile(string loadFilePath, string saveFileDial, int key) { FileStream saveFileStream = null; FileStream openFileStream = new FileStream(loadFilePath, FileMode.Open, FileAccess.Read, FileShare.None, 100000); BinaryReader reader = new BinaryReader(openFileStream); long length = new FileInfo(loadFilePath).Length; long[] massProcess = new long[3]; massProcess[0] = openFileStream.Length; string extension = Path.GetExtension(loadFilePath); if (key == 2 && extension == ".crypt") { string filePathDecrypt = loadFilePath.Remove(loadFilePath.Length - 6); extension = filePathDecrypt.Substring(filePathDecrypt.LastIndexOf(".")); saveFileStream = new FileStream(saveFileDial + extension, FileMode.Create, FileAccess.Write); } else { saveFileStream = new FileStream(saveFileDial + extension + ".crypt", FileMode.Create, FileAccess.Write); } ProgressStr prsttr = new ProgressStr { massProcess = massProcess, openFileStream = openFileStream }; TimerCallback tm = new TimerCallback(CountTimerProgress); System.Threading.Timer timerPr = new Timer(tm, prsttr, 0, 20); BinaryWriter readerSave = new BinaryWriter(saveFileStream); byte[] buffer = new byte[100]; int bufferSize = buffer.Length; while (reader.BaseStream.Position != reader.BaseStream.Length) { for (int i = 0; i < bufferSize; i++) { if (reader.BaseStream.Position != reader.BaseStream.Length) { buffer[i] = reader.ReadByte(); } else { bufferSize = i; } } buffer = Encode(buffer, bufferSize); for (int i = 0; i < bufferSize; i++) { readerSave.Write(buffer[i]); } } //Циклически побайтно шифруем или расшифровываем файл Thread.Sleep(21); timerPr.Dispose(); openFileStream.Close(); saveFileStream.Close(); } //Шифрование и расшифрование файла