public int Read(byte[] buffer, int offset, int count) { if (_inputBuffer.Count < count) { var readBuffer = _readBuffer; int read; try { read = _dataProvider.Read(readBuffer, 0, readBuffer.Length); } catch (IOException) { IOFailed = true; throw; } if (read != 0) { if (_decryptor != null) { _decryptor.ProcessBytes(readBuffer, 0, read, readBuffer, 0); } if (_decompressor != null) { read = HandleDecompression(readBuffer, read); readBuffer = _compressionBuffer; } WriteToInputBuffer(readBuffer, read); } } var dataLength = ReadFromInputBuffer(buffer, offset, count); return(dataLength); }
public void Flush() { var buffer = _outputBuffer.ToArray(); _outputBuffer.Clear(); var count = buffer.Length; if (_compressor != null) { count = HandleCompression(buffer, count); buffer = _compressionBuffer; } if (_encryptor != null) { _encryptor.ProcessBytes(buffer, 0, count, buffer, 0); } try { _dataProvider.Write(buffer, 0, count); _dataProvider.Flush(); } catch (IOException) { IOFailed = true; throw; } }
public void DecodeCryptogram(string key) { byte[] result = new byte[cryptogramByte.Count]; byte[] pass = Encoding.ASCII.GetBytes(key); try { RC4Engine rc4 = new RC4Engine(); KeyParameter keyParam = new KeyParameter(pass); rc4.Init(true, keyParam); rc4.ProcessBytes(cryptogramByte.ToArray(), 0, cryptogramByte.Count, result, 0); } catch (Exception e) { Console.WriteLine(e.Message); } if (CheckDecryptedText(result)) { Console.Write("klucz: " + key + ": "); foreach (var c in result) { if (c != 0) { Console.Write((char)c); } } Console.WriteLine(); } }
public void ThreadRun() { int i = 0; byte[] clearText = new byte[kryptogram.Length]; string czescKlucza1 = ""; while (i <= szukaj.max) { i = szukaj.wykonane(); if (i <= szukaj.max) { czescKlucza1 = i.ToString("X"); while (czescKlucza1.Length < 8) { czescKlucza1 = "0" + czescKlucza1; } String klucz = czescKlucza1.ToLower() + czescKlucza2; try { RC4Engine rc4 = new RC4Engine(); KeyParameter keyParam = new KeyParameter(System.Text.Encoding.ASCII.GetBytes(klucz)); rc4.Init(false, keyParam); rc4.ProcessBytes(kryptogram, 0, kryptogram.Length, clearText, 0); } catch (Exception e) { } bool zgodne = true; for (int j = 0; j < clearText.Length; j++) { if (!alfabet.lista_znakow.Contains((char)clearText[j])) { zgodne = false; } } //jeśli znalazl dobry klucz if (zgodne) { Console.Write("Wiadomosc : "); foreach (byte x in clearText) { Console.Write("{0} ", (char)x); } Console.WriteLine(""); Console.WriteLine(" klucz: {0}",klucz); szukaj.ileZrobiono = szukaj.max; } } } }