Ejemplo n.º 1
0
        private static Color handleBpccSelectionHeader(int bpcc, Color sourcePixelColor)
        {
            var binaryBpcc =
                BinaryDecimalConverter.CalculateBinaryForBpcc(bpcc);

            sourcePixelColor.G = (byte)binaryBpcc;

            return(sourcePixelColor);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Extracts the message from image.
        /// </summary>
        /// <param name="embeddedPixels">The embedded pixels.</param>
        /// <param name="embeddedImageWidth">Width of the embedded image.</param>
        /// <param name="embeddedImageHeight">Height of the embedded image.</param>
        /// @Precondition none
        /// @Postcondition message is extracted from the image
        public override async Task ExtractMessageFromImage(byte[] embeddedPixels, uint embeddedImageWidth,
                                                           uint embeddedImageHeight)
        {
            var encryptionPassword = new StringBuilder();
            var count = 0;

            for (var currY = 0; currY < embeddedImageHeight; currY++)
            {
                for (var currX = 0; currX < embeddedImageWidth; currX++)
                {
                    var embeddedPixelColor = PixelColorInfo.GetPixelBgra8(embeddedPixels, currY, currX,
                                                                          embeddedImageWidth);

                    if (isFirstPixel(currY, currX))
                    {
                        if (embeddedPixelColor.R == 212 && embeddedPixelColor.B == 212 &&
                            embeddedPixelColor.G == 212)
                        {
                            continue;
                        }

                        await Dialogs.ShowNoMessageDialog();

                        return;
                    }

                    if (isSecondPixel(currY, currX))
                    {
                        EncryptionUsed = (embeddedPixelColor.R & 1) != 0;
                        this.endOfEncryptionKeyReached = !EncryptionUsed;
                        this.bpcc = BinaryDecimalConverter.CalculateBpccFromBinary(embeddedPixelColor.G);

                        var numberOfBits = (embeddedImageWidth * embeddedImageHeight - 2) *
                                           PixelConstants.NumberOfColorChannels * this.bpcc;
                        this.embeddedBits = new BitArray((int)numberOfBits);
                    }
                    else
                    {
                        if (this.endOfMessageReached)
                        {
                            this.handleReachedEndOfMessage(encryptionPassword);
                            return;
                        }

                        this.extractMessageBitsFromPixel(embeddedPixelColor, count);
                        count += PixelConstants.NumberOfColorChannels * this.bpcc;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Construction()
        {
            // arrange

            // act
            var converter = new BinaryDecimalConverter();

            // assert
            Assert.NotNull(converter);
            Assert.Null(converter.Binary);
            Assert.Null(converter.Decimal);
            Assert.Null(converter.ErrorMessage);
            Assert.Equal("none", converter.ErrorDisplay);
        }
Ejemplo n.º 4
0
        public void ConvertBinary_WithDecimalString(
            string initialDecimal, string expectedBinary, string expectedErrorMessage, string expectedErrorDisplay)
        {
            // arrange
            var converter = new BinaryDecimalConverter
            {
                Decimal = initialDecimal
            };

            // act
            converter.ConvertBinary();

            // assert
            Assert.Equal(expectedBinary, converter.Binary);
            Assert.Equal(expectedErrorMessage, converter.ErrorMessage);
            Assert.Equal(expectedErrorDisplay, converter.ErrorDisplay);
        }
Ejemplo n.º 5
0
        public void ConvertDecimal_WithBinaryString(
            string initialBinary, string expectedDecimal, string expectedErrorMessage, string expectedErrorDisplay)
        {
            // arrange
            var converter = new BinaryDecimalConverter
            {
                Binary = initialBinary
            };

            // act
            converter.ConvertDecimal();

            // assert
            Assert.Equal(expectedDecimal, converter.Decimal);
            Assert.Equal(expectedErrorMessage, converter.ErrorMessage);
            Assert.Equal(expectedErrorDisplay, converter.ErrorDisplay);
        }