Exemple #1
0
        public void Insert_T(object bmp, bool useOpap)
        {
            DateTime start = DateTime.Now;
            Opap     methodOPAP = new Opap();
            Bitmap   bmap = (Bitmap)bmp;
            int      k = 0, i = 0, j = 0, p = 0;
            int      newR, newG, newB;
            int      bitSelect = bitSelecT, bitMove;
            Color    theColor    = new Color();
            Color    originColor = new Color();
            int      msgL        = message.Length;
            int      intCounter  = 0;

            //calcul de pas
            float stop = ((float)msgL * 8) / ((float)bitSelect * 3);

            if (8 % bitSelect != 0)
            {
                int stopPixelL = (bitSelect - (8 % bitSelect)) * msgL;
                stop = (((float)msgL * 8) + (float)stopPixelL) / ((float)bitSelect * 3);
            }

            if (stop % 1 != 0)
            {
                stop++;
            }
            int stride = (bmap.Height * bmap.Width - reserved) / (int)stop;



            //insertion du watermark "YOZ" sur 4 pixels debut

            string watermarked = "yoz";


            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 1;
            newG     = theColor.G - theColor.G % 4 + 2;
            newB     = theColor.B - theColor.B % 4 + 3;
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 1;
            newG     = theColor.G - theColor.G % 4 + 3;
            newB     = theColor.B - theColor.B % 4 + 3;
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 2;
            newG     = theColor.G - theColor.G % 4 + 1; //if crypted we insert "yoc" instead of "yoz"
            newB     = theColor.B - theColor.B % 4 + 2; if (crypted)
            {
                newB = theColor.B - theColor.B % 4 + 3;
            }
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 2; if (crypted)
            {
                newR = theColor.R - theColor.R % 4 + 0;
            }
            newG = theColor.G - theColor.G % 4 + 3; if (crypted)
            {
                newG = theColor.G - theColor.G % 4 + 2;
            }
            newB = theColor.B - theColor.B % 4 + 1; if (crypted)
            {
                newB = theColor.B - theColor.B % 4 + 1;
            }
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;



            //insertion de la taille sur 6 pixels

            while (intCounter < 30)
            {
                theColor = bmap.GetPixel(j, i);
                newR     = theColor.R - theColor.R % 4 + msgL % 4;
                msgL   >>= 2;
                newG     = theColor.G - theColor.G % 4 + msgL % 4;
                msgL   >>= 2;
                newB     = theColor.B - theColor.B % 4 + msgL % 4;
                msgL   >>= 2;
                theColor = Color.FromArgb(newR, newG, newB);
                bmap.SetPixel(j, i, theColor);
                j++;
                intCounter += 6;
            }

            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + msgL % 4; // 31 +32 eme bit du int
            int temp = bitSelect;

            newG   = theColor.G - theColor.G % 4 + temp % 4; // 4 bits pour le bitSelect
            temp >>= 2;
            newB   = theColor.B - theColor.B % 4 + temp % 4;

            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);

            j = reserved;


            //insertion du message
            for (k = 0; k < message.Length; k++)
            {
                char letter  = Convert.ToChar(message.Substring(k, 1));
                int  letterI = Convert.ToInt32(letter);

                bitMove = bitSelect;
                while ((bitMove - bitSelect) < 8)
                {
                    theColor    = bmap.GetPixel(j, i);
                    originColor = theColor;


                    while (p < 3 && (bitMove - bitSelect) < 8)
                    {
                        switch (p)
                        {
                        case 0:
                            newR      = theColor.R - theColor.R % (int)Math.Pow(2, bitSelect);
                            newR     += letterI % (int)Math.Pow(2, bitSelect);
                            letterI >>= bitSelect;
                            theColor  = Color.FromArgb(newR, theColor.G, theColor.B);

                            break;

                        case 1:
                            newG      = theColor.G - theColor.G % (int)Math.Pow(2, bitSelect);
                            newG     += letterI % (int)Math.Pow(2, bitSelect);
                            letterI >>= bitSelect;
                            theColor  = Color.FromArgb(theColor.R, newG, theColor.B);

                            break;

                        case 2:
                            newB      = theColor.B - theColor.B % (int)Math.Pow(2, bitSelect);
                            newB     += letterI % (int)Math.Pow(2, bitSelect);
                            letterI >>= bitSelect;
                            theColor  = Color.FromArgb(theColor.R, theColor.G, newB);

                            break;
                        }

                        bitMove += bitSelect;
                        p++;
                    }

                    bmap.SetPixel(j, i, theColor);
                    if (useOpap)
                    {
                        bmap.SetPixel(j, i, methodOPAP.OPAP(originColor, theColor, bitSelect));
                    }

                    if (p == 3)
                    {
                        p = 0;
                        if (j + stride <= bmap.Width - 1)
                        {
                            j += stride;
                        }
                        else
                        {
                            int stridesLeft;
                            stridesLeft = stride - (bmap.Width - 1 - j);
                            i++;

                            while (stridesLeft > bmap.Width)
                            {
                                stridesLeft -= bmap.Width;
                                i++;
                            }

                            j = stridesLeft - 1;
                        }
                    }
                }
            }

            TimeSpan timeItTook = DateTime.Now - start;

            Console.WriteLine("Time elapsed : Minutes: {0}  Seconds: {1} Milliseconds: {2}", timeItTook.Minutes, timeItTook.Seconds, timeItTook.Milliseconds);
            crypted = false;
            OnImageFinished(bmap, null);
        }
Exemple #2
0
        public void Insert_F(object bmp, bool useOpap)
        {
            Opap   methodOPAP = new Opap();
            Bitmap bmap = (Bitmap)bmp;
            int    k = 0, i = 0, j = 0, p = 0;
            int    newR, newG, newB;
            int    bitSelect = bitSelecT, bitMove;
            Color  theColor    = new Color();
            Color  originColor = new Color();
            int    msgL        = FileBytes.Length;
            int    intCounter  = 0;

            //calcul de pas
            float stop = ((float)msgL * 8) / ((float)bitSelect * 3);

            if (8 % bitSelect != 0)
            {
                int stopPixelL = (bitSelect - (8 % bitSelect)) * msgL;
                stop = (((float)msgL * 8) + (float)stopPixelL) / ((float)bitSelect * 3);
            }

            if (stop % 1 != 0)
            {
                stop++;
            }
            int stride = (bmap.Height * bmap.Width - reserved) / (int)stop;



            //insertion du watermark "ZOY" sur 4 pixels debut

            string watermarked = "zoy";


            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 2;
            newG     = theColor.G - theColor.G % 4 + 2;
            newB     = theColor.B - theColor.B % 4 + 3;
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 1;
            newG     = theColor.G - theColor.G % 4 + 3;
            newB     = theColor.B - theColor.B % 4 + 3;
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 2;
            newG     = theColor.G - theColor.G % 4 + 1; //if crypted we insert "zoc" instead of "zoy"
            newB     = theColor.B - theColor.B % 4 + 1; if (crypted)
            {
                newB = theColor.B - theColor.B % 4 + 3;
            }
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;
            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + 2; if (crypted)
            {
                newR = theColor.R - theColor.R % 4 + 0;
            }
            newG = theColor.G - theColor.G % 4 + 3; if (crypted)
            {
                newG = theColor.G - theColor.G % 4 + 2;
            }
            newB = theColor.B - theColor.B % 4 + 1; if (crypted)
            {
                newB = theColor.B - theColor.B % 4 + 1;
            }
            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);
            j++;



            //insertion de la taille sur 6 pixels

            while (intCounter < 30)
            {
                theColor = bmap.GetPixel(j, i);
                newR     = theColor.R - theColor.R % 4 + msgL % 4;
                msgL   >>= 2;
                newG     = theColor.G - theColor.G % 4 + msgL % 4;
                msgL   >>= 2;
                newB     = theColor.B - theColor.B % 4 + msgL % 4;
                msgL   >>= 2;
                theColor = Color.FromArgb(newR, newG, newB);
                bmap.SetPixel(j, i, theColor);
                j++;
                intCounter += 6;
            }

            theColor = bmap.GetPixel(j, i);
            newR     = theColor.R - theColor.R % 4 + msgL % 4; // 31 +32 eme bit du int
            int temp = bitSelect;

            newG   = theColor.G - theColor.G % 4 + temp % 4; // 4 bits pour le bitSelect
            temp >>= 2;
            newB   = theColor.B - theColor.B % 4 + temp % 4;

            theColor = Color.FromArgb(newR, newG, newB);
            bmap.SetPixel(j, i, theColor);

            j = reserved;


            //insertion du message
            for (k = 0; k < FileBytes.Length; k++)
            {
                int fileByte = FileBytes[k];


                bitMove = bitSelect;
                while ((bitMove - bitSelect) < 8)
                {
                    theColor    = bmap.GetPixel(j, i);
                    originColor = theColor;


                    while (p < 3 && (bitMove - bitSelect) < 8)
                    {
                        switch (p)
                        {
                        case 0:
                            newR       = theColor.R - theColor.R % (int)Math.Pow(2, bitSelect);
                            newR      += fileByte % (int)Math.Pow(2, bitSelect);
                            fileByte >>= bitSelect;
                            theColor   = Color.FromArgb(newR, theColor.G, theColor.B);

                            break;

                        case 1:
                            newG       = theColor.G - theColor.G % (int)Math.Pow(2, bitSelect);
                            newG      += fileByte % (int)Math.Pow(2, bitSelect);
                            fileByte >>= bitSelect;
                            theColor   = Color.FromArgb(theColor.R, newG, theColor.B);

                            break;

                        case 2:
                            newB       = theColor.B - theColor.B % (int)Math.Pow(2, bitSelect);
                            newB      += fileByte % (int)Math.Pow(2, bitSelect);
                            fileByte >>= bitSelect;
                            theColor   = Color.FromArgb(theColor.R, theColor.G, newB);

                            break;
                        }

                        bitMove += bitSelect;
                        p++;
                    }

                    bmap.SetPixel(j, i, theColor);
                    if (useOpap)
                    {
                        bmap.SetPixel(j, i, methodOPAP.OPAP(originColor, theColor, bitSelect));
                    }

                    if (p == 3)
                    {
                        p = 0;
                        if (j + stride <= bmap.Width - 1)
                        {
                            j += stride;
                        }
                        else
                        {
                            int stridesLeft;
                            stridesLeft = stride - (bmap.Width - 1 - j);
                            i++;

                            while (stridesLeft > bmap.Width)
                            {
                                stridesLeft -= bmap.Width;
                                i++;
                            }

                            j = stridesLeft - 1;
                        }
                    }
                }
            }

            crypted = false;
            OnImageFinished(bmap, null);
        }