10:29 Steganography practical implementation of hiding data in bmp format using net | |
Hello. In connection with the recent post about steganography I want to talk about the practical side of the issue. The easiest way to hide somewhere in the data - this is shove them into bmp file. Why BMP?BMP to represent colors using a color model RGB, ie, color, which sees the person is obtained by mixing three colors, Red, Green, Blue (red, green, blue), and BMP formats typically do not use compression, which allows you to hide it quite a lot of information. How to hide the information?Each color (pixel) is encoded by a single byte (8 bits). We have these three colors (red, blue, green), total 3 bytes (24 bits). To write down our information and does not distort the image, we will write to the lower bits of the image. Ie we take the pixel, we explain it to the colors and replace the lower bits bits of our message. I will explain the scheme: This is 1 byte of our message: 10101010 This is our pixel RGB: R: 11110000 G: 00001000 B: 11001000 replace the lower bits and obtain a new pixel: R: 11110010 G: 00001101 B: 11,001 ~ ~> 010 ~ ~>> This operation will not make the image visible to the human eye distortion.Consider a software implementation on. Net framework. Software Implementation net in the software implementation will greatly assist us in namespace System.Drawing.have a wonderful class Color that will help dismantle the color pixel model is RGB. Consider the function of writing data to the file:, Bitmap image = Image.FromFile ("C: \ \ image.bmp"); string message = "Message"; void BmpWrite () { / / pixel image Color pixel; int x = 0 / / Read the message * byte [] B = Encoding . GetEncoding (1251). GetBytes (message +'/'); bool f = false; / / pass on the image for (int i = 0; i <image.Width ; i + +) { if (f) break; for (int j = 0; j <image.Height; j + +) { / / Grab pixel pixel = image.GetPixel (i, j); / / If you encrypt the entire message, quit if (x == B. Length) {f = true; break;} / / byte messages represent an array of bits (see above example 11001100) Bits m = new Bits (B [x ++]); / / with up to 8 bits while (m.Length! = 8) m.Insert (0, 0) / / get each color of RGB, and if necessary, with up to 8 bits Bits r = new Bits (pixel.R); while (r.Length! = 8) r.Insert (0, 0); Bits g = new Bits (pixel.G); while (g.Length! = 8) g.Insert (0, 0) ; Bits b = new Bits (pixel.B); while (b.Length! = 8) b.Insert (0, 0) / / replace the corresponding lower bits bits of our messages r [6] = m [0]; r [7] = m [1]; g [5] = m [2]; g [6] = m [ 3]; g [7] = m [4]; b [5] = m [5]; b [6] = m [6]; b [7] = m [7] / / Write pixel back into the picture image.SetPixel (i, j, Color.FromArgb (r.Number, g.Number, b.Number)); } } } * This source code was highlighted with Source Code Highlighter. * Byte [] B = Encoding.GetEncoding (1251). GetBytes (message +'/'); - this line we have added our message symbol '/' - this is done for so that when pulling out our message from the file, we knew how long we read the message, because we really do not know its length. Of course, this is not the most elegant option, you can use other rare special character, and preferably in the first pixel to indicate the length of the message, but this task I'll leave you. So uncomplicated way we recorded our message in a bmp-file, now read it: Bitmap image = Image.FromFile ("C: \ \ image_secret.bmp"); void BmpRead () { / / pixel image Color pixel; / / bytes are read message ArrayList array = new ArrayList (); bool f = false; / / iterate over the image for (int i = 0; i <image.Width; i + +) { if (f) break; for ( int j = 0; j <image.Height; j + +) { / / Grab the pixel pixel = image.GetPixel (i, j); / / Current readable B Bits m = new Bits (255); / / get each color of RGB, and if necessary, with up to 8 bits Bits r = new Bits (pixel.R); while (r . Length! = 8) r.Insert (0, 0); Bits g = new Bits (pixel.G); while (g.Length! = 8) g.Insert (0, 0) Bits b = new Bits (pixel.B); while (b.Length! = 8) b.Insert (0, 0) / / Read the lower bits m [0] = r [6]; m [1] = r [7]; m [2] = g [5]; m [3] = g [6] m [4] = g [7]; m [5] = b [5]; m [6] = b [6]; m [7] = b [7 ] / / If you meet our special character, then reached the end of the message, go if (m.Char == '/') {f = true; break;} / / Reads a byte translate into the number of array.Add (m.Number); } } byte [] msg = new byte [array.Count]; / / Translate message in bytes, because we received a message in a numeric representation of byte for (int i = 0; i <array.Count; i + +) msg [i] = Convert.ToByte (array [i]); / / And here is our message string message = Encoding.GetEncoding (1251). GetString (msg); } * This source code was highlighted with Source Code Highlighter. * Implementation class Bits can be found in the attached source code. Data can be read and write more cunningly, and not follow the straight lines of pixel image. For example, you can write strictly on the edges of an image or a more clever pixel traversal algorithm, which will increase the reliability of the system. Little about AVI It is worth mentioning that the avi without compression is consequent bmp, so this algorithm can be adapted to video AVI. An example implementation is in the attached source code. The source code that implements the techniques described above can be found here. Thank you for your attention. | |
|
Total comments: 0 | |