0

I'm making a simple steganography program to hide data in PNG files. Decoding/encoding single bytes was easy, but I also need to hide a header in the PNG file. This header will contain the filesize in bytes to know exactly how many bytes I need to extract the file (too many bytes and tge extracted file will be corrupted).

So I need to break the integer into single bytes (since integers in FB is 32 bits wide, this will result in four separate bytes). Then these bytes will be encoded into the first 16 pixels of the PNG image (in my steganography algorithm 1 decoded byte = 4 encoded and I use only R and B values for data storage). How might I do this?

TL;DR: I need to know how to break integers into four individual bytes and then merge those bytes into integers again.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Dariusz G. Jagielski
  • 655
  • 3
  • 11
  • 22

1 Answers1

1

My friend on FB forums, Mysoft created this example how to do that. Also, thanks for responsiveness and quick answer stackoverflow's community.

dim as integer x = &hFF88442211, y
dim as integer b1,b2,b3,b4

b1 =  x and &hFF
b2 = (x shr 8) and &hFF
b3 = (x shr 16) and &hFF
b4 = (x shr 24) and &hFF

y = b1+(b2 shl 8)+(b3 shl 16)+(b4 shl 24)

print hex$(x),hex$(y)
print hex$(b1),hex$(b2),hex$(b3),hex$(b4)
Dariusz G. Jagielski
  • 655
  • 3
  • 11
  • 22
  • 2
    Its probably a good idea to include the code in your answer. This way you can avoid Link Rot – Conrad Frix Nov 15 '11 at 19:09
  • I didn't know whether is it against SO rules or not, so posted link to pastebin just to be sure. Most programming sites I visit prefer pastebin links rather than embeded code. – Dariusz G. Jagielski Nov 15 '11 at 20:31
  • Having an answer stand on its own is preferred. Including code in questions and answer is encouraged. In fact the site users google code prettify and does syntax highlighting based on the question tags, although Freebasic isn't on the [supported list for highlighting](http://meta.stackexchange.com/questions/981/syntax-highlighting-language-hints) – Conrad Frix Nov 15 '11 at 20:56