Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How Can I Hide Data In An Image Using Skin Tone Based Staganography
i have used this one..but it shows many errors...
class SteganographyHelper
{
enum State
{
hiding,
filling_with_zeros
};

public static Bitmap embedText(string text, Bitmap bmp)
{
State s = State.hiding;

int charIndex = 0;
int charValue = 0;
long colorUnitIndex = 0;

int zeros = 0;

int R = 0, G = 0, B = 0;

for (int i = 0; i < bmp.Height; i++)
{
for (int j = 0; j < bmp.Width; j++)
{
Color pixel = bmp.GetPixel(j, i);

pixel = Color.FromArgb(pixel.R - pixel.R % 2,
pixel.G - pixel.G % 2, pixel.B - pixel.B % 2);

R = pixel.R; G = pixel.G; B = pixel.B;

for (int n = 0; n < 3; n++)
{
if (colorUnitIndex % 8 == 0)
{
if (zeros == 8)
{
if ((colorUnitIndex - 1) % 3 < 2)
{
bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
}

return bmp;
}

if (charIndex >= text.Length)
{
s = State.filling_with_zeros;
}
else
{
charValue = text[charIndex++];
}
}

switch (colorUnitIndex % 3)
{
case 0:
{
if (s == State.hiding)
{
R += charValue % 2;

charValue /= 2;
}
} break;
case 1:
{
if (s == State.hiding)
{
G += charValue % 2;

charValue /= 2;
}
} break;
case 2:
{
if (s == State.hiding)
{
B += charValue % 2;

charValue /= 2;
}

bmp.SetPixel(j, i, Color.FromArgb(R, G, B));
} break;
}

colorUnitIndex++;

if (s == State.filling_with_zeros)
{
zeros++;
}
}
}
}

return bmp;
}

public static string extractText(Bitmap bmp)
{
int colorUnitIndex = 0;
int charValue = 0;

string extractedText = String.Empty;

for (int i = 0; i < bmp.Height; i++)
{
for (int j = 0; j < bmp.Width; j++)
{
Color pixel = bmp.GetPixel(j, i);

for (int n = 0; n < 3; n++)
{
switch (colorUnitIndex % 3)
{
case 0:
{
charValue = charValue * 2 + pixel.R % 2;
} break;
case 1:
{
charValue = charValue * 2 + pixel.G % 2;
} break;
case 2:
{
charValue = charValue * 2 + pixel.B % 2;
} break;
}

colorUnitIndex++;

if (colorUnitIndex % 8 == 0)
{
charValue = reverseBits(charValue);

if (charValue == 0)
{
return extractedText;
}

char c = (char)charValue;

extractedText += c.ToString();
}
}
}
}

return extractedText;
}

public static int reverseBits(int n)
{
int result = 0;

for (int i = 0; i < 8; i++)
{
result = result * 2 + n % 2;

n /= 2;
}

return result;
}
}
Posted

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