コード例 #1
0
        public byte[] Extract(DigitalAudio stegoAudio)
        {
            int[] primeSignal;
            using (WavReader reader = new WavReader(File.OpenRead(PrimeSignalFilePath)))
                primeSignal = reader.ReadAudio().GetSignal();
            var stegoSignal       = stegoAudio.GetSignal();
            int samplesPerSegment = (int)Math.Floor((double)stegoSignal.Length / (MessageLength * 8));

            var rnd = new Random(RandomSeed); int lseg, rseg;

            int[]       pseudoRandomSignal = new int[samplesPerSegment];
            var         difference = new double[samplesPerSegment];
            List <bool> message = new List <bool>();
            double      primeMean = 0, difMean = 0;

            for (int i = 0; (i + 1) * samplesPerSegment <= stegoSignal.Length; i++)
            {
                lseg = i * samplesPerSegment;
                rseg = samplesPerSegment * (i + 1);
                RndSignal(rnd, pseudoRandomSignal);
                for (int j = lseg, k = 0; j < rseg; j++, k++)
                {
                    primeSignal[j] = (int)(primeSignal[j] * 0.95);

                    difference[k] = (stegoSignal[j] - primeSignal[j]) * pseudoRandomSignal[k];
                    primeMean    += primeSignal[j];
                    difMean      += stegoSignal[j];
                }
                message.Add(Math.Sign(primeMean) == Math.Sign(difMean));
                primeMean = 0; difMean = 0;
            }
            return(BitArrayToByteArray(new BitArray(message.ToArray())));
        }
コード例 #2
0
        public void OpenWAV()
        {
            OutputLogs logs = OutputLogs.Instance();

            OpenFileDialogService.Filter      = "Wav Files (.wav)|*.wav|All Files (*.*)|*.*";
            OpenFileDialogService.FilterIndex = 1;
            OpenFileDialogService.Title       = "Open target audio";
            if (OpenFileDialogService.ShowDialog())
            {
                IFileInfo file   = OpenFileDialogService.Files.First();
                WavReader reader = null;
                try
                {
                    reader        = new WavReader(File.Open(file.GetFullName(), FileMode.Open, FileAccess.Read, FileShare.None));
                    Audio         = reader.ReadAudio();
                    AudioFileName = file.Name;
                    string msg = string.Concat("Succesfully loaded file - ", file.GetFullName());
                    logs.AddLog(new Message(MessageType.Info, msg, "WavReader"));
                }
                catch (ApplicationException ex)
                {
                    logs.AddLog(new Message(MessageType.Error, ex.Message, ex.Source));
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                }
            }
        }