Click here to Skip to main content
15,888,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have encoded a message in the lsb of each pixel. How would i retrieve it? When i read the LSB of each pixel do input each bit into a byte array or a zero/one into a char array? Unsure what encoding function to call then? I should use a foreach loop and Encoding.UTF8.GetString(Message)but all the ones and zeros from the char array into a single string?

I have just modified my code. The message i pull form the image i put into a
stringbuilder object consist of ones and zeros. After the indexed for loops, one can see i have tried various methods but the same value is returned, any suggestions
C#
private void button2_Click(object sender, EventArgs e)
        {
            int c = sb.Length,x,y,z=0;
            char[] Message= new char[c];
            StringBuilder RetreivedMessage = new StringBuilder();
            for (x = 0, y = 0; x < image1.Width && z < c; x++)
            {
                for (y = 0; y < image1.Height && z < c; y++)
                {
                    Color pixelColor = image1.GetPixel(x, y);
                    string binary1 = Convert.ToString(pixelColor.R, 2);
                    //byte NewRed, NewGreen, NewBlue;
                    if (binary1[binary1.Length -1] == '0')
                    {
                        RetreivedMessage.Append('0');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    else
                    {
                        RetreivedMessage.Append('1');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    binary1 = Convert.ToString(pixelColor.G, 2);
                    //byte NewRed, NewGreen, NewBlue;
                    if (binary1[binary1.Length - 1] == '0')
                    {
                        RetreivedMessage.Append('0');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    else
                    {
                        RetreivedMessage.Append('1');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    binary1 = Convert.ToString(pixelColor.B, 2);
                    //byte NewRed, NewGreen, NewBlue;
                    if (binary1[binary1.Length - 1] == '0')
                    {
                        RetreivedMessage.Append('0');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    else
                    {
                        RetreivedMessage.Append('1');
                        z++;
                        if (z == c)
                        {
                            break;
                        }

                    }
                    //string binary1 = Convert.ToString(pixelColor.R, 2);
                    //char last1 = binary1[binary1.Length - 1];
                }
            }
            string FinalRetreivedMessage  = RetreivedMessage.ToString();
            //Byte[] buf = Encoding.Unicode.GetBytes(RetreivedMessage.ToString());
            Byte[] buf = Encoding.Unicode.GetBytes(RetreivedMessage.ToString());
            string result = System.Text.Encoding.Unicode.GetString(buf);
            //String result = Encoding.Unicode.GetString(buf);
            StringBuilder r2 = new StringBuilder();
            //foreach (Byte b in Encoding.Unicode.GetBytes(FinalRetreivedMessage))
           // {
           //    r2.Append(Convert.ToString());
            //}
        }
Posted
v3
Comments
Christian Graus 18-Nov-12 15:53pm    
You reverse the process you used to put it in there, surely ?
Darith1974 21-Nov-12 5:07am    
string a ="te";
StringBuilder r2 = new StringBuilder();
foreach (Byte b in Encoding.Unicode.GetBytes(a))
{
r2.Append(Convert.ToString(b,2));
}

Thanks your reply has substance in that i used the above code to create the initial string so i should look at this code to solve my challenge

string FinalRetreivedMessage  = RetreivedMessage.ToString();
            int count = FinalRetreivedMessage.Length / 8;
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            UTF8Encoding enc = new UTF8Encoding();
            var StringBytes = new byte[count];
            for (int i = 0; i < count; i++)
                StringBytes[i] = Convert.ToByte(FinalRetreivedMessage.Substring(i * 8, 8), 2);
                //StringBytes[i] = encoding.GetBytes(FinalRetreivedMessage.Substring(i * 8, 8), 2);
            string FinalResult = enc.GetString(StringBytes);
 
Share this answer
 
string FinalRetreivedMessage  = RetreivedMessage.ToString();
            int count = FinalRetreivedMessage.Length / 8;
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            UTF8Encoding enc = new UTF8Encoding();
            var StringBytes = new byte[count];
            for (int i = 0; i < count; i++)
                StringBytes[i] = Convert.ToByte(FinalRetreivedMessage.Substring(i * 8, 8), 2);
                //StringBytes[i] = encoding.GetBytes(FinalRetreivedMessage.Substring(i * 8, 8), 2);
            string FinalResult = enc.GetString(StringBytes);
 
Share this answer
 
Comments
Gbolahan OIladele Taiwo 10-May-16 0:16am    
Hello Hamzeh Soboh. I downloaded your code on steganography (c#) to guide me to development mine for my project yet i'm trying to run it. How do i run your code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900