コード例 #1
0
        /// <summary>
        /// HOWTO: Enter the algorithm you'd like to implement in this method.
        /// </summary>
        public void Execute()
        {
            // no progress, yet
            ProgressChanged(0, 1);

            if (InputCarrier == null)
            {
                GuiLogMessage("Please specify an input file.", NotificationLevel.Error);
                return;
            }

            using (CStreamReader midiReader = InputCarrier.CreateReader())
            {
                MemoryStream    secretStream;
                MemoryStream    outputStream = new MemoryStream();
                MidiFileHandler midiHandler  = new MidiFileHandler();

                switch (settings.Action)
                {
                case 0:         // Encryption
                    using (CStreamReader messageReader = InputData.CreateReader())
                    {
                        secretStream = new MemoryStream(messageReader.ReadFully());
                        midiHandler.HideOrExtract(midiReader, secretStream, new MemoryStream(), outputStream, (byte)(settings.MaxMessageBytesPerCarrierUnit * 2), false);
                    }
                    OutputCarrier = new CStreamWriter(outputStream.ToArray());
                    OnPropertyChanged("OutputCarrier");
                    break;

                case 1:         // Decryption
                    secretStream = new MemoryStream();
                    midiHandler.HideOrExtract(midiReader, secretStream, new MemoryStream(), outputStream, 1, true);
                    //OutputData = new CStreamWriter(secretStream.GetBuffer());

                    secretStream.Position = 0;
                    using (StreamReader secretReader = new StreamReader(secretStream))
                    {
                        OutputText = secretReader.ReadToEnd();
                        OnPropertyChanged("OutputText");
                    }
                    break;
                }
            }

            // HOWTO: After you have changed an output property, make sure you announce the name of the changed property to the CT2 core.
            //OnPropertyChanged("Difference");

            // HOWTO: You can pass error, warning, info or debug messages to the CT2 main window.
            //if (settings.Subtrahend < 0)
            //    GuiLogMessage("Subtrahend is negative", NotificationLevel.Debug);

            // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully.
            ProgressChanged(1, 1);
        }
コード例 #2
0
        /// <summary>
        /// Reads the carrier image and calls Hide/Extract.
        /// </summary>
        public void Execute()
        {
            ProgressChanged(0, 1);

            if (InputCarrier == null)
            {
                GuiLogMessage("Please provide an input carrier.", NotificationLevel.Error);
                return;
            }

            if (InputPassword == null || InputPassword.Length == 0)
            {
                GuiLogMessage("Please provide a password.", NotificationLevel.Error);
                return;
            }

            if (InputData == null && settings.Action == 0)
            {
                GuiLogMessage("Please provide a message.", NotificationLevel.Error);
                return;
            }

            currentColorComponent = 0;

            using (CStreamReader reader = InputCarrier.CreateReader())
            {
                using (Bitmap bitmap = new Bitmap(reader))
                {
                    switch (settings.Action)
                    {
                    case 0:     // hide message
                        this.imageInfo = null;

                        //make sure that the image is in RGB format
                        Bitmap image = PaletteToRGB(bitmap);

                        if (settings.CustomizeRegions)
                        {
                            hidedialog = new RegionHideForm(image, (int)InputData.Length);
                            if (hidedialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                            {
                                return;
                            }
                            this.imageInfo = hidedialog.ImageInfo;
                        }

                        if (this.imageInfo == null)
                        {
                            CreateDefaultImageInfo(image);

                            if (imageInfo.Capacity < InputData.Length)
                            {
                                GuiLogMessage("The defined regions can only hold " + imageInfo.Capacity + " bytes of information, but the input consists of " + InputData.Length + " bytes.", NotificationLevel.Error);
                                return;
                            }

                            GuiLogMessage("The carrier image can hide " + imageInfo.Capacity + " bytes of information.", NotificationLevel.Info);
                        }

                        Hide(image, InputData.CreateReader(), InputPassword.CreateReader());
                        OnPropertyChanged("OutputCarrier");
                        break;

                    case 1:     // extract message
                        try
                        {
                            Extract(bitmap, InputPassword.CreateReader());
                            OnPropertyChanged("OutputData");

                            if (settings.ShowRegions)
                            {
                                extractdialog = new RegionExtractForm(this.imageInfo);
                                extractdialog.ShowDialog();
                            }
                        }
                        catch (Exception ex)
                        {
                            GuiLogMessage("Wrong key or nothing hidden in the picture", NotificationLevel.Warning);
                            return;
                        }
                        break;
                    }
                }
            }

            ProgressChanged(1, 1);
        }