Jump to content
  • Advertisement
Sign in to follow this  
LordFallout

another bitwise operator question

This topic is 4167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i have a binary pattern written to a file, it is written backwards . . so 11000101 is written to the file, 1 then 0 then 1 then 0 etc. I want to read this binary back from the file into an unsigned char, however i need to read it back into a varibale backwards too, so i need to read it in 1 then 0 then 1 then 0 and store the result as an unsigned char, i think i might need to use bitwise operations but im not too sure any help would be lovely. Thank you [Edited by - LordFallout on March 23, 2007 2:30:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
So, did you get what you wanted, or not? If not, please post the input, the expected result, and the actual result.

Share this post


Link to post
Share on other sites
Ok, well i have two text files and an image, i hide one text file in an image by changing random pixels, i change the LSB of each pixel too match a single bit of text byte, for a file with 1 byte of text, i.e one character of type unsigned char i store 8 bits within the picture i tried to hide this text

This is a Hidden text message, it is not hidden anymore.

and recieved this text

This is a Hidden text message, it ) J Rp6>hÊF

it is the right size just somwhere the text gets muddled up. I input the binary like so


RandX = new int[FileSize * 8];
RandY = new int[FileSize * 8];
RandomGenerator->GetPairs( RandX, RandY, FileSize * 8, Dest->Picture->Bitmap->Width, Dest->Picture->Bitmap->Height );

for (int y=0; y < Dest->Picture->Bitmap->Height; y++)
{
for (int x=0; x < Dest->Picture->Bitmap->Width; x++)
{
if( x == RandX[PixelIndex] && y == RandY[PixelIndex] )
{
int shiftedNumber = buffer[n];
BinNumber = (shiftedNumber >> i) & 1;

Pixel.Colours = Dest->Canvas->Pixels[x][y];
ColorToRGB(Pixel.Colours);

CurrentColour = GetRValue(Pixel.Channel.Red);

CurrentColour = CurrentColour & ~1 | BinNumber;

Pixel.Channel.Red = CurrentColour;

Dest->Canvas->Pixels[x][y] = Pixel.Colours;
Pixel.Colours = Dest->Canvas->Pixels[x][y];
ColorToRGB(Pixel.Colours);

CurrentColour = GetRValue(Pixel.Channel.Red);

PixelIndex++;
x = 0;
y = 0;
i++;
if( i > 7 )
{
n++;
i = 0;
}
}
}
}




and output like so


RandX = new int[FileSize * 8];
RandY = new int[FileSize * 8];
RandomGenerator->GetPairs( RandX, RandY, FileSize * 8, Dest->Picture->Bitmap->Width, Dest->Picture->Bitmap->Height );

for (int y=0; y < Dest->Picture->Bitmap->Height; y++)
{
for (int x=0; x < Dest->Picture->Bitmap->Width; x++)
{
if( x == RandX[PixelIndex] && y == RandY[PixelIndex] )
{
Pixel.Colours = Dest->Canvas->Pixels[x][y];
ColorToRGB(Pixel.Colours);

CurrentColour = GetRValue(Pixel.Channel.Red);

BinNumber = (CurrentColour >> 0) & 1;
buffer[n] |= BinNumber << i;

PixelIndex++;

x = 0;
y = 0;
i++;
if( i > 7 )
{
buffer[n + 1] = 0;
n++;
i = 0;
}
}
}
}




I cant really understand how only some of the text gets messed up, i can provide more of an explanation if needed. It confuses me a little typing it haha

edit: the filesize is set depending on the size of the input file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!