예제 #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);
            }
        }
예제 #2
0
        private void handleExtractLetter(int count)
        {
            if (count % 8 != 7)
            {
                return;
            }

            var currIndex = 0;
            var peekBits  = new BitArray(this.numberOfBitsInByte);

            for (var k = count; k >= count - 7; k--)
            {
                peekBits.Set(currIndex, this.embeddedBits.Get(k));
                currIndex++;
            }

            var extractedLetter = BinaryStringConverter.BitArrayToString(peekBits);

            if (this.peek.Length == this.numberOfBitsInByte && this.endOfEncryptionKeyReached)
            {
                this.embeddedMessage.Append(this.peek.ToString().Substring(0, 1));
                this.peek.Remove(0, 1);
            }
            else if (this.peek.Length == this.numberOfBitsInByte)
            {
                this.encryptionKey.Append(this.peek.ToString().Substring(0, 1));
                this.peek.Remove(0, 1);
            }

            this.peek.Append(extractedLetter);

            if (this.endOfEncryptionKeyReached)
            {
                this.checkForEndOfMessage();
            }
            else
            {
                this.checkForEndOfEncryptionKey();
            }
        }
 public void Setup() => _converter = new BinaryStringConverter();