Esempio n. 1
0
        /// <summary>
        ///     Embeds the message.
        /// </summary>
        /// @Precondition this.messageFile != null && this.sourceFile != null
        /// @Postcondition message is embedded and shown in the program
        /// <param name="encryptionSelected">if set to <c>true</c> [encryption selected].</param>
        /// <param name="bpcc">The BPCC.</param>
        /// <param name="encryptionKey">The encryption key.</param>
        public async Task EmbedMessage(bool encryptionSelected, int bpcc, string encryptionKey)
        {
            if (this.messageFile.FileType == FileTypeConstants.TextFileType)
            {
                string formattedText;
                if (encryptionSelected)
                {
                    formattedText =
                        EmbedTextFormatter.FormatEncryptedTextForEmbedding(encryptionKey, this.TextFromFile);
                }
                else
                {
                    formattedText = EmbedTextFormatter.FormatTextForEmbedding(this.TextFromFile);
                }

                var binaryText    = BinaryStringConverter.ConvertStringToBinary(formattedText);
                var messageLength = binaryText.Length;

                await this.messageEmbedder.EmbedMessageInImage(binaryText, (uint)messageLength, 0,
                                                               this.sourceImageWidth, this.sourceImageHeight, encryptionSelected, bpcc);
            }
            else
            {
                var messageDecoder =
                    await BitmapDecoder.CreateAsync(await this.messageFile.OpenAsync(FileAccessMode.Read));

                var messagePixels = await PixelExtracter.ExtractPixelDataFromFile(this.messageFile);

                var messageImageWidth  = messageDecoder.PixelWidth;
                var messageImageHeight = messageDecoder.PixelHeight;

                await this.messageEmbedder.EmbedMessageInImage(messagePixels, messageImageWidth, messageImageHeight,
                                                               this.sourceImageWidth, this.sourceImageHeight, encryptionSelected, bpcc);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Loads the message.
        ///     @Precondition none
        ///     @Postcondition message file is loaded into the program
        /// </summary>
        public async Task LoadMessage()
        {
            this.messageFile = await this.fileReader.SelectMessageFile();

            if (this.messageFile == null)
            {
                return;
            }

            if (this.MessageFileType.Equals(FileTypeConstants.TextFileType))
            {
                this.messageEmbedder = new TextMessageEmbedder();
                this.TextFromFile    = await this.fileReader.ReadTextFromFile(this.messageFile);
            }
            else
            {
                this.messageEmbedder = new MonochromeImageEmbedder();
                this.MessageImage    = await FileBitmapConverter.ConvertFileToBitmap(this.messageFile);
            }

            if (this.SourceImage != null)
            {
                var sourceImagePixels = await PixelExtracter.ExtractPixelDataFromFile(this.sourceImageFile);

                this.messageEmbedder.SourceImagePixels = sourceImagePixels;
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Loads the source image.
        ///     @Precondition none
        ///     @Postcondition source image is loaded into the program
        /// </summary>
        public async Task LoadSourceImage()
        {
            this.sourceImageFile = await this.fileReader.SelectSourceImageFile();

            if (this.sourceImageFile == null)
            {
                return;
            }

            var sourceImage = await FileBitmapConverter.ConvertFileToBitmap(this.sourceImageFile);

            this.SourceImage = sourceImage;

            var sourceImagePixels = await PixelExtracter.ExtractPixelDataFromFile(this.sourceImageFile);

            this.messageEmbedder.SourceImagePixels = sourceImagePixels;

            await this.setSourceImageSizeValues();
        }
Esempio n. 4
0
        /// <summary>
        ///     Extracts the message.
        /// </summary>
        /// @Precondition this.embeddedImageFile != null
        /// @Postcondition message is extracted from image
        public async Task ExtractMessage()
        {
            var embeddedPixels = await PixelExtracter.ExtractPixelDataFromFile(this.EmbeddedImageFile);

            var embeddedDecoder =
                await BitmapDecoder.CreateAsync(await this.EmbeddedImageFile.OpenAsync(FileAccessMode.Read));

            var fileTypeEmbedded =
                EmbeddedMessageFileTypeExtractor.DetermineFileTypeToExtract(embeddedPixels, embeddedDecoder.PixelWidth);

            if (fileTypeEmbedded == FileTypes.Text)
            {
                this.messageExtracter = new TextFileExtracter();
            }
            else
            {
                this.messageExtracter = new MonochromeImageExtracter();
            }

            await this.setExtractedImageSizeValues();

            await this.messageExtracter.ExtractMessageFromImage(embeddedPixels, embeddedDecoder.PixelWidth,
                                                                embeddedDecoder.PixelHeight);
        }