// реализация кнопки, отвечающей за дешифровку сообщения из зашифрованного файла private void button3_Click(object sender, EventArgs e) { WavFile wavFile = new WavFile(); FileStream fsr = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fsr); wavFile.sGroupID = r.ReadChars(4); wavFile.dwFileLength = r.ReadUInt32(); wavFile.sRiffType = r.ReadChars(4); wavFile.sFChunkID = r.ReadChars(4); wavFile.dwFChunkSize = r.ReadUInt32(); wavFile.wFormatTag = r.ReadUInt16(); wavFile.wChannels = r.ReadUInt16(); wavFile.dwSamplesPerSec = r.ReadUInt32(); wavFile.dwAvgBytesPerSec = r.ReadUInt32(); wavFile.wBlockAlign = r.ReadUInt16(); wavFile.wBitsPerSample = r.ReadUInt16(); wavFile.sDChunkID = r.ReadChars(4); wavFile.dwDChunkSize = r.ReadUInt32(); wavFile.dataStartPos = (byte)r.BaseStream.Position; r.Close(); fsr.Close(); string decodedMessage = wavFile.EncryptFile(textBox1.Text); richTextBox2.Text = decodedMessage; }
private void button2_Click(object sender, EventArgs e) { WavFile wavFile = new WavFile(); FileStream fsr = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fsr); wavFile.sGroupID = r.ReadChars(4); wavFile.dwFileLength = r.ReadUInt32(); wavFile.sRiffType = r.ReadChars(4); wavFile.sFChunkID = r.ReadChars(4); wavFile.dwFChunkSize = r.ReadUInt32(); wavFile.wFormatTag = r.ReadUInt16(); wavFile.wChannels = r.ReadUInt16(); wavFile.dwSamplesPerSec = r.ReadUInt32(); wavFile.dwAvgBytesPerSec = r.ReadUInt32(); wavFile.wBlockAlign = r.ReadUInt16(); wavFile.wBitsPerSample = r.ReadUInt16(); wavFile.sDChunkID = r.ReadChars(4); wavFile.dwDChunkSize = r.ReadUInt32(); wavFile.dataStartPos = (byte)r.BaseStream.Position; r.Close(); fsr.Close(); SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "Wav files (*.WAV)|*.wav"; int bytesPerSample = Convert.ToInt32(textBox4.Text) / 8; if (saveFile.ShowDialog() == DialogResult.OK) { textBox5.Text = saveFile.FileName.ToString(); //wavFile.WriteWav(textBox1.Text, textBox5.Text); wavFile.WriteFile(textBox1.Text, textBox5.Text, richTextBox1.Text); } }
public string Analyze(WavFile file2, string path1, string path2) { byte DataPos1 = this.dataStartPos; byte DataPos2 = file2.dataStartPos; byte[] source1, source2; using (BinaryReader b1 = new BinaryReader(File.Open(path1, FileMode.Open))) { int length1 = (int)b1.BaseStream.Length; source1 = b1.ReadBytes(length1); } using (BinaryReader b2 = new BinaryReader(File.Open(path2, FileMode.Open))) { int length2 = (int)b2.BaseStream.Length; source2 = b2.ReadBytes(length2); } int arrlen = source1.Length - (DataPos1 + 1); int[] NumberArray = new int[arrlen]; for (int i = 0; i < arrlen; i++) { NumberArray[i] = 0; } string str = "Номера измененных байтов данных в файле:"; int step = 0; for (int i = DataPos2 + 1; i < source2.Length; i++) { if (source2[i] != source1[i]) { NumberArray[step] = i; step++; } } for (int i = 0; i < arrlen; i++) { if (NumberArray[i] != 0) { str += " " + Convert.ToString(NumberArray[i]); } } if (str == "Номера измененных байтов данных в файле:") { str = "В части аудиоданных файла изменений нет."; } return(str); }
private void button4_Click(object sender, EventArgs e) { WavFile wavFile1 = new WavFile(); FileStream fsr = new FileStream(textBox11.Text, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fsr); wavFile1.sGroupID = r.ReadChars(4); wavFile1.dwFileLength = r.ReadUInt32(); wavFile1.sRiffType = r.ReadChars(4); wavFile1.sFChunkID = r.ReadChars(4); wavFile1.dwFChunkSize = r.ReadUInt32(); wavFile1.wFormatTag = r.ReadUInt16(); wavFile1.wChannels = r.ReadUInt16(); wavFile1.dwSamplesPerSec = r.ReadUInt32(); wavFile1.dwAvgBytesPerSec = r.ReadUInt32(); wavFile1.wBlockAlign = r.ReadUInt16(); wavFile1.wBitsPerSample = r.ReadUInt16(); wavFile1.sDChunkID = r.ReadChars(4); wavFile1.dwDChunkSize = r.ReadUInt32(); wavFile1.dataStartPos = (byte)r.BaseStream.Position; r.Close(); fsr.Close(); WavFile wavFile2 = new WavFile(); FileStream fsr1 = new FileStream(textBox12.Text, FileMode.Open, FileAccess.Read); BinaryReader r1 = new BinaryReader(fsr1); wavFile2.sGroupID = r1.ReadChars(4); wavFile2.dwFileLength = r1.ReadUInt32(); wavFile2.sRiffType = r1.ReadChars(4); wavFile2.sFChunkID = r1.ReadChars(4); wavFile2.dwFChunkSize = r1.ReadUInt32(); wavFile2.wFormatTag = r1.ReadUInt16(); wavFile2.wChannels = r1.ReadUInt16(); wavFile2.dwSamplesPerSec = r1.ReadUInt32(); wavFile2.dwAvgBytesPerSec = r1.ReadUInt32(); wavFile2.wBlockAlign = r1.ReadUInt16(); wavFile2.wBitsPerSample = r1.ReadUInt16(); wavFile2.sDChunkID = r1.ReadChars(4); wavFile2.dwDChunkSize = r1.ReadUInt32(); wavFile2.dataStartPos = (byte)r1.BaseStream.Position; r1.Close(); fsr1.Close(); richTextBox3.Text = wavFile1.Analyze(wavFile2, textBox11.Text, textBox12.Text); }
// при открытии файла сразу будем получать исходные данные о нём private void button1_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Wav files (*.WAV)|*.wav"; if (dialog.ShowDialog() == DialogResult.OK) { textBox1.Text = dialog.FileName.ToString(); // считываем wav файл, получаем его характеристики, выводим нужные в текстбокс WavFile wavFile = new WavFile(); FileStream fsr = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fsr); wavFile.sGroupID = r.ReadChars(4); wavFile.dwFileLength = r.ReadUInt32(); wavFile.sRiffType = r.ReadChars(4); wavFile.sFChunkID = r.ReadChars(4); wavFile.dwFChunkSize = r.ReadUInt32(); wavFile.wFormatTag = r.ReadUInt16(); wavFile.wChannels = r.ReadUInt16(); wavFile.dwSamplesPerSec = r.ReadUInt32(); wavFile.dwAvgBytesPerSec = r.ReadUInt32(); wavFile.wBlockAlign = r.ReadUInt16(); wavFile.wBitsPerSample = r.ReadUInt16(); wavFile.sDChunkID = r.ReadChars(4); wavFile.dwDChunkSize = r.ReadUInt32(); wavFile.dataStartPos = (byte)r.BaseStream.Position; r.Close(); fsr.Close(); textBox2.Text = Convert.ToString(wavFile.dwSamplesPerSec) + " Гц"; textBox3.Text = Convert.ToString(wavFile.wChannels); textBox4.Text = Convert.ToString(wavFile.wBitsPerSample); textBox6.Text = Convert.ToString(wavFile.dwDChunkSize) + " Байт"; textBox7.Text = Convert.ToString(wavFile.dataStartPos); textBox8.Text = Convert.ToString(wavFile.dwFChunkSize); textBox9.Text = Convert.ToString(wavFile.wBlockAlign); textBox10.Text = Convert.ToString(wavFile.dwAvgBytesPerSec); } }