public AudioFile DecodeHiddenMessage(AudioFile containerAudioFile) { var hiddenBitsPerSample = containerAudioFile.waveFile.bitsPerSample / CHANGING_SAMPLES_FACTOR; var hiddenMessageBits = new BitArray((int)(containerAudioFile.waveFile.samples.Length * hiddenBitsPerSample)); var maxNumberOfDecodingSteps = containerAudioFile.waveFile.samples.Length; for (int i = 0; i < maxNumberOfDecodingSteps; i++) { var uintValue = containerAudioFile.waveFile.samples[i]; var intFromBitsToRead = uintValue.GetLastNBitsIntValue((int) hiddenBitsPerSample); var hiddenIntBits = new BitArray(new[] { intFromBitsToRead }).GetBitArrayFromBitArrayRange(0, (int) hiddenBitsPerSample); for(int j = 0; j < hiddenIntBits.Length; j++) { hiddenMessageBits.Set(i * (int) hiddenBitsPerSample + j, hiddenIntBits[j]); } } containerAudioFile.waveFile.Save(); var messageBytes = new byte[hiddenMessageBits.Count]; hiddenMessageBits.CopyTo(messageBytes, 0); return new AudioFile(containerAudioFile.bytes, messageBytes); }
public AudioFile CreateHiddenMessage(AudioFile containerAudioFile, byte[] messageToHide) { _waveCodingValidator.CheckIfCanHideMessageOrThrow(containerAudioFile, messageToHide); var bitsFromMessageToSave = TextUtils.GetMessageBitArray(messageToHide); var bitsPerSampleThatCanBeHide = containerAudioFile.waveFile.bitsPerSample / CHANGING_SAMPLES_FACTOR; var hidingSteps = bitsFromMessageToSave.Length / bitsPerSampleThatCanBeHide; var samples = containerAudioFile.waveFile.samples; for (int i = 0; i < hidingSteps; i++) { var bitsToPut = bitsFromMessageToSave.GetBitArrayFromBitArrayRange((int)(i * bitsPerSampleThatCanBeHide), (int) bitsPerSampleThatCanBeHide); samples[i] = samples[i].PutBitsAsLSB(bitsToPut); } containerAudioFile.waveFile.Save(); return new AudioFile(containerAudioFile.bytes); }
public void CheckIfCanHideMessageOrThrow(AudioFile containerAudioFile, byte[] messageToHide) { var bitsFromMessageToSave = TextUtils.GetMessageBitArray(messageToHide); if (containerAudioFile.waveFile.bitsPerSample != 8 && containerAudioFile.waveFile.bitsPerSample != 16 && containerAudioFile.waveFile.bitsPerSample != 24 && containerAudioFile.waveFile.bitsPerSample != 32) { throw new Exception("Nieprawidłowa liczba bitów na próbkę! Wspierane: 8/16/24"); } var audioCapacity = containerAudioFile.waveFile.samples.Length * (containerAudioFile.waveFile.bitsPerSample / WaveCoding.CHANGING_SAMPLES_FACTOR); if (bitsFromMessageToSave.Length > audioCapacity) throw new Exception("Wiadomość jest zbyt długa aby umieścić ją w pliku .wav" + Environment.NewLine + "Długość wiadomości w bajtach: " + bitsFromMessageToSave.Length + Environment.NewLine + "Ilośc dostępnego miejsca w pliku audio: " + audioCapacity); if (containerAudioFile.waveFile.samples.Count() <= 10) throw new Exception("Niepoprawny plik audio!"); }
public void Clear() { _hiddenMessageAudioFile = null; NotifyOfPropertyChange(() => HiddenMessage); }
public HiddenMessageAudioViewModel(AudioFile hiddenMessageAudioFile) { _hiddenMessageAudioFile = hiddenMessageAudioFile; }