Exemplo n.º 1
0
        public static Color GetColor(Color pixel, bool [] tab)
        {
            var pixelR = ByteArrayExtension.Set2LastBits(pixel.R, tab[0], tab[1]);
            var pixelG = ByteArrayExtension.SetLastBit(pixel.G, tab[2]);
            var pixelB = ByteArrayExtension.SetLastBit(pixel.B, tab[3]);

            return(Color.FromArgb(pixel.A, pixelR, pixelG, pixelB));
        }
Exemplo n.º 2
0
        public Bitmap ReadImage(Bitmap image)
        {
            List <byte> hidden = new List <byte>();

            byte[] byteArray;
            byte   bajt = 0;

            byte[] end_word = Encoding.UTF8.GetBytes("STOP_DECRYPTING_THE_PICTURE");
            int    k        = 0;

            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j += 2)
                {
                    var      pixel  = image.GetPixel(i, j);
                    var      pixel1 = image.GetPixel(i, j + 1);
                    BitArray bits   = new BitArray(
                        new bool[]
                    {
                        ByteArrayExtension.GetBit(pixel.R, 1),
                        ByteArrayExtension.GetBit(pixel.R, 0),
                        ByteArrayExtension.GetBit(pixel.G, 0),
                        ByteArrayExtension.GetBit(pixel.B, 0),
                        ByteArrayExtension.GetBit(pixel1.R, 1),
                        ByteArrayExtension.GetBit(pixel1.R, 0),
                        ByteArrayExtension.GetBit(pixel1.G, 0),
                        ByteArrayExtension.GetBit(pixel1.B, 0)
                    });

                    bajt = EncryptionHelper.ConvertToByte(bits);
                    if (bajt == end_word[k])
                    {
                        k++;
                    }
                    else
                    {
                        k = 0;
                    }

                    hidden.Add(bajt);


                    if (k == 27)
                    {
                        break;
                    }
                }
                if (k == 27)
                {
                    break;
                }
            }

            hidden.RemoveRange(hidden.Count - 27, 27);

            byteArray = hidden.ToArray();

            using (MemoryStream ms = new MemoryStream(byteArray))
            {
                Bitmap img = (Bitmap)Image.FromStream(ms);
                return(img);
            }
        }