Exemplo n.º 1
0
        public new Bitmap Extract(String sPath)
        {
            SimpleObjectFactory sof = new SimpleObjectFactory();

            IImageFile cimg    = sof.getImageFile();
            Bitmap     cbmp    = cimg.getBitMap(sPath);
            int        cwidth  = cimg.getWidth(sPath);
            int        cheight = cimg.getHeight(sPath);

            int    cx = 0, cy = 0;
            string swidth = null, sheight = null;

            for (int i = 0; i < 5; i++)
            {
                Color lp = cbmp.GetPixel(cx, cy);
                int   ca = lp.A;
                int   cr = lp.R;
                int   cg = lp.G;
                int   cb = lp.B;
                swidth += (cr % 2).ToString();
                swidth += (cg % 2).ToString();
                swidth += (cb % 2).ToString();
                cx++;
            }


            for (int i = 0; i < 5; i++)
            {
                Color lp = cbmp.GetPixel(cx, cy);
                int   ca = lp.A;
                int   cr = lp.R;
                int   cg = lp.G;
                int   cb = lp.B;
                sheight += (cr % 2).ToString();
                sheight += (cg % 2).ToString();
                sheight += (cb % 2).ToString();
                cx++;
            }


            int sw = Convert.ToInt32(swidth, 2);
            int sh = Convert.ToInt32(sheight, 2);

            Bitmap s = new Bitmap(sw, sh);

            for (int i = 0; i < sh; i++)
            {
                for (int j = 0; j < sw; j++)
                {
                    string all = null;
                    for (int k = 0; k < 11; k++)
                    {
                        Color lp = cbmp.GetPixel(cx, cy);
                        int   ca = lp.A;
                        int   cr = lp.R;
                        int   cg = lp.G;
                        int   cb = lp.B;

                        all += (cr % 2).ToString();
                        all += (cg % 2).ToString();
                        all += (cb % 2).ToString();

                        cx++;
                        if (cx == cwidth)
                        {
                            cx = 0; cy++;
                        }
                    }
                    string alpha = all.Substring(0, 8);
                    int    sa    = Convert.ToInt32(alpha, 2);
                    string red   = all.Substring(8, 8);
                    int    sr    = Convert.ToInt32(red, 2);
                    string green = all.Substring(16, 8);
                    int    sg    = Convert.ToInt32(green, 2);
                    string blue  = all.Substring(24, 8);
                    int    sb    = Convert.ToInt32(blue, 2);

                    s.SetPixel(j, i, Color.FromArgb(sa, sr, sg, sb));
                }
            }

            return(s);
        }
Exemplo n.º 2
0
        public Bitmap Embedd(string path, string msg)
        {
            String binMsg = "";

            for (int i = 0; i < msg.Length; i++)
            {
                binMsg += Convert.ToString(msg[i], 2).PadLeft(8, '0');
            }
            binMsg += "11111111";

            SimpleObjectFactory sof       = new SimpleObjectFactory();
            IImageFile          ImageFile = sof.getImageFile();
            Bitmap bmp      = ImageFile.getBitMap(path);
            int    width    = ImageFile.getWidth(path);
            int    height   = ImageFile.getHeight(path);
            int    binIndex = 0;
            int    flag     = 0;

            IImageFile sImage = sof.getImageFile();
            Bitmap     eMap   = sImage.getBitMap(path);

            for (int y = 0; y < height && flag == 0; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color p = bmp.GetPixel(x, y);

                    int a = p.A;
                    int r = p.R;
                    int g = p.G;
                    int b = p.B;

                    if (int.Parse(binMsg[binIndex].ToString()) != r % 2)
                    {
                        if (binMsg[binIndex] == '0')
                        {
                            r--;
                        }
                        else
                        {
                            r++;
                        }
                    }
                    eMap.SetPixel(x, y, Color.FromArgb(a, r, g, b));
                    binIndex++;
                    if (binIndex == binMsg.Length)
                    {
                        flag = 1; break;
                    }
                    if (int.Parse(binMsg[binIndex].ToString()) != g % 2)
                    {
                        if (binMsg[binIndex] == '0')
                        {
                            g--;
                        }
                        else
                        {
                            g++;
                        }
                    }
                    eMap.SetPixel(x, y, Color.FromArgb(a, r, g, b));
                    binIndex++;
                    if (binIndex == binMsg.Length)
                    {
                        flag = 1; break;
                    }
                    if (int.Parse(binMsg[binIndex].ToString()) != b % 2)
                    {
                        if (binMsg[binIndex] == '0')
                        {
                            b--;
                        }
                        else
                        {
                            b++;
                        }
                    }
                    eMap.SetPixel(x, y, Color.FromArgb(a, r, g, b));
                    binIndex++;
                    if (binIndex == binMsg.Length)
                    {
                        flag = 1; break;
                    }
                }
            }


            return(eMap);
        }
Exemplo n.º 3
0
        public Bitmap Embedd(String cPath, String sPath)
        {
            SimpleObjectFactory sof = new SimpleObjectFactory();

            IImageFile imgs    = sof.getImageFile();
            Bitmap     bmps    = imgs.getBitMap(sPath);
            int        widths  = imgs.getWidth(sPath);
            int        heights = imgs.getHeight(sPath);

            IImageFile imgc    = sof.getImageFile();
            Bitmap     bmpc    = imgs.getBitMap(cPath);
            int        widthc  = imgs.getWidth(cPath);
            int        heightc = imgs.getHeight(cPath);

            Bitmap eMap = imgc.getBitMap(cPath);

            int cx = 0, cy = 0;

            long   len  = widths;
            string blen = Convert.ToString(len, 2);

            while (blen.Length != 15)
            {
                blen = "0" + blen;
            }

            len = heights;
            string stemp = Convert.ToString(len, 2);

            while (stemp.Length != 15)
            {
                stemp = "0" + stemp;
            }

            blen = blen + stemp;

            for (int r = 0; r < 10; r++)
            {
                Color lp = eMap.GetPixel(cx, cy);
                int   ca = lp.A;
                int   cr = lp.R;
                int   cg = lp.G;
                int   cb = lp.B;

                if (int.Parse(blen[3 * r].ToString()) != cr % 2)
                {
                    if (blen[3 * r] == '0')
                    {
                        cr--;
                    }
                    else
                    {
                        cr++;
                    }
                }
                if (int.Parse(blen[(3 * r) + 1].ToString()) != cg % 2)
                {
                    if (blen[(3 * r) + 1] == '0')
                    {
                        cg--;
                    }
                    else
                    {
                        cg++;
                    }
                }
                if (int.Parse(blen[(3 * r) + 2].ToString()) != cb % 2)
                {
                    if (blen[(3 * r) + 2] == '0')
                    {
                        cb--;
                    }
                    else
                    {
                        cb++;
                    }
                }
                eMap.SetPixel(cx, cy, Color.FromArgb(ca, cr, cg, cb));
                cx++;
            }


            for (int y = 0; y < heights; y++)
            {
                for (int x = 0; x < widths; x++)
                {
                    Color p = bmps.GetPixel(x, y);

                    int a = p.A;
                    int r = p.R;
                    int g = p.G;
                    int b = p.B;

                    string temp = null;
                    string sa   = Convert.ToString(a, 2);
                    while (sa.Length != 8)
                    {
                        sa = "0" + sa;
                    }
                    string sr = Convert.ToString(r, 2);
                    while (sr.Length != 8)
                    {
                        sr = "0" + sr;
                    }
                    string sg = Convert.ToString(g, 2);
                    while (sg.Length != 8)
                    {
                        sg = "0" + sg;
                    }
                    string sb = Convert.ToString(b, 2);
                    while (sb.Length != 8)
                    {
                        sb = "0" + sb;
                    }
                    //int cflag = 0;
                    temp = sa + sr + sg + sb + "0";
                    for (int m = 0; m < 11; m++)
                    {
                        Color cp = eMap.GetPixel(cx, cy);
                        int   ca = cp.A;
                        int   cr = cp.R;
                        int   cg = cp.G;
                        int   cb = cp.B;

                        if (int.Parse(temp[3 * m].ToString()) != cr % 2)
                        {
                            if (temp[3 * m] == '0')
                            {
                                cr--;
                            }
                            else
                            {
                                cr++;
                            }
                        }
                        if (int.Parse(temp[(3 * m) + 1].ToString()) != cg % 2)
                        {
                            if (temp[(3 * m) + 1] == '0')
                            {
                                cg--;
                            }
                            else
                            {
                                cg++;
                            }
                        }
                        if (int.Parse(temp[(3 * m) + 2].ToString()) != cb % 2)
                        {
                            if (temp[(3 * m) + 2] == '0')
                            {
                                cb--;
                            }
                            else
                            {
                                cb++;
                            }
                        }
                        eMap.SetPixel(cx, cy, Color.FromArgb(ca, cr, cg, cb));
                        cx++;
                        if (cx == widthc)
                        {
                            cx = 0; cy++;
                        }
                    }
                }
            }

            return(eMap);
        }
Exemplo n.º 4
0
        public string Extract(string path)
        {
            SimpleObjectFactory sof       = new SimpleObjectFactory();
            IImageFile          ImageFile = sof.getImageFile();
            Bitmap bmp = ImageFile.getBitMap(path);
            int    width = bmp.Width;
            int    height = bmp.Height;
            int    flag = 0;
            String msg = "", binMsg = "";

            //IImageFile sImage = sof.getImageFile();
            //Bitmap eMap = sImage.getBitMap(path);

            for (int y = 0; y < height && flag == 0; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Color p = bmp.GetPixel(x, y);

                    int a = p.A;
                    int r = p.R;
                    int g = p.G;
                    int b = p.B;

                    binMsg += (r % 2).ToString();
                    if (binMsg.Length > 8)
                    {
                        if (binMsg.Substring(binMsg.Length - 8, 8).Equals("11111111") && binMsg.Length % 8 == 0)
                        {
                            flag = 1; break;
                        }
                    }

                    binMsg += (g % 2).ToString();
                    if (binMsg.Length > 8)
                    {
                        if (binMsg.Substring(binMsg.Length - 8, 8).Equals("11111111") && binMsg.Length % 8 == 0)
                        {
                            flag = 1; break;
                        }
                    }

                    binMsg += (b % 2).ToString();
                    if (binMsg.Length > 8)
                    {
                        if (binMsg.Substring(binMsg.Length - 8, 8).Equals("11111111") && binMsg.Length % 8 == 0)
                        {
                            flag = 1; break;
                        }
                    }
                }
            }


            if (binMsg.Substring(binMsg.Length - 8, 8).Equals("11111111") && binMsg.Length % 8 == 0)
            {
                binMsg = binMsg.Remove(binMsg.Length - 8);

                for (int i = 0; i < binMsg.Length; i += 8)
                {
                    msg += (char)(128 * int.Parse(binMsg[i].ToString()) + 64 * int.Parse(binMsg[i + 1].ToString()) + 32 * int.Parse(binMsg[i + 2].ToString()) + 16 * int.Parse(binMsg[i + 3].ToString()) + 8 * int.Parse(binMsg[i + 4].ToString()) + 4 * int.Parse(binMsg[i + 5].ToString()) + 2 * int.Parse(binMsg[i + 6].ToString()) + int.Parse(binMsg[i + 7].ToString()));
                }
            }
            else
            {
                msg = "";
                MessageBox.Show("No Message Found.");
            }

            return(msg);
        }