Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1.  
  2. public static void ImageNormalizeColours(string input, string output)
  3. {
  4. System.Drawing.Bitmap inputbm = new System.Drawing.Bitmap(input);
  5. int h = 0;
  6. for (int image_height = 0; image_height < inputbm.Height; image_height++)
  7. {
  8. for (int image_width = 0; image_width < inputbm.Width; image_width++)
  9. {
  10. System.Drawing.Color pixel_colour = inputbm.GetPixel(image_width, image_height);
  11. if (pixel_colour.R > h) h = pixel_colour.R;
  12. if (pixel_colour.G > h) h = pixel_colour.G;
  13. if (pixel_colour.B > h) h = pixel_colour.B;
  14. }
  15. }
  16. for (int image_height = 0; image_height < inputbm.Height; image_height++)
  17. {
  18. for (int image_width = 0; image_width < inputbm.Width; image_width++)
  19. {
  20. System.Drawing.Color pixel_colour = inputbm.GetPixel(image_width, image_height);
  21. int r = 255 / h * pixel_colour.R;
  22. int g = 255 / h * pixel_colour.G;
  23. int b = 255 / h * pixel_colour.B;
  24. pixel_colour = System.Drawing.Color.FromArgb(r, g, b);
  25. inputbm.SetPixel(image_width, image_height, pixel_colour);
  26. }
  27. }
  28. inputbm.Save(output);
  29. }
  30.  
  31. public static void TwoLSBSteganographyInserter(string inputImageFilename, System.Drawing.Bitmap imageToHide, string outputImageFilename)
  32. {
  33. System.Drawing.Bitmap input = new System.Drawing.Bitmap(inputImageFilename);
  34.  
  35. for (int image_height = 0; image_height < imageToHide.Height; image_height++)
  36. {
  37. for (int image_width = 0; image_width < imageToHide.Width; image_width++)
  38. {
  39. System.Drawing.Color pixel_colour = imageToHide.GetPixel(image_width, image_height);
  40.  
  41. int pixel_byte_r = pixel_colour.R;
  42. int pixel_byte_g = pixel_colour.G;
  43. int pixel_byte_b = pixel_colour.B;
  44.  
  45. int small_byte_r = SteganographyCompressColourPart(pixel_byte_r, 255, 4) - 1;
  46. string binary_r = ByteToBinary(small_byte_r).Substring(6, 2);
  47.  
  48. int small_byte_g = SteganographyCompressColourPart(pixel_byte_g, 255, 4) - 1;
  49. string binary_g = ByteToBinary(small_byte_g).Substring(6, 2);
  50.  
  51. int small_byte_b = SteganographyCompressColourPart(pixel_byte_b, 255, 4) - 1;
  52. string binary_b = ByteToBinary(small_byte_b).Substring(6, 2);
  53.  
  54. System.Drawing.Color input_pixel_colour = input.GetPixel(image_width, image_height);
  55.  
  56. int input_pixel_byte_r = input_pixel_colour.R;
  57. int input_pixel_byte_g = input_pixel_colour.G;
  58. int input_pixel_byte_b = input_pixel_colour.B;
  59.  
  60. string input_pixel_binary_r = Generic.ByteToBinary(input_pixel_byte_r);
  61. string input_pixel_binary_g = Generic.ByteToBinary(input_pixel_byte_g);
  62. string input_pixel_binary_b = Generic.ByteToBinary(input_pixel_byte_b);
  63.  
  64. input_pixel_binary_r = input_pixel_binary_r.Substring(0, 6) + binary_r;
  65. input_pixel_binary_g = input_pixel_binary_g.Substring(0, 6) + binary_g;
  66. input_pixel_binary_b = input_pixel_binary_b.Substring(0, 6) + binary_b;
  67.  
  68. input_pixel_byte_r = BinaryToByte(input_pixel_binary_r);
  69. input_pixel_byte_g = BinaryToByte(input_pixel_binary_g);
  70. input_pixel_byte_b = BinaryToByte(input_pixel_binary_b);
  71.  
  72. input_pixel_colour = System.Drawing.Color.FromArgb(input_pixel_byte_r, input_pixel_byte_g, input_pixel_byte_b);
  73.  
  74. input.SetPixel(image_width, image_height, input_pixel_colour);
  75. }
  76. }
  77.  
  78. input.Save(outputImageFilename);
  79. }
  80.  
  81. public static void TwoLSBSteganographyExtractor(string input)
  82. {
  83. string output = input + ".out." + input.Substring(input.Length - 3, 3);
  84. TwoLSBSteganographyExtractor(input, output);
  85. }
  86.  
  87. public static void TwoLSBSteganographyExtractor(string input, string output)
  88. {
  89. System.Drawing.Bitmap image_bitmap = Generic.CreateNonIndexedImage(new System.Drawing.Bitmap(input));
  90. for (int image_height = 0; image_height < image_bitmap.Height; image_height++)
  91. {
  92. for (int image_width = 0; image_width < image_bitmap.Width; image_width++)
  93. {
  94. System.Drawing.Color pixel_colour = image_bitmap.GetPixel(image_width, image_height);
  95.  
  96. int pixel_byte_r = pixel_colour.R;
  97. int pixel_byte_g = pixel_colour.G;
  98. int pixel_byte_b = pixel_colour.B;
  99.  
  100. string pixel_binary_r = Generic.ByteToBinary(pixel_byte_r);
  101. string pixel_binary_g = Generic.ByteToBinary(pixel_byte_g);
  102. string pixel_binary_b = Generic.ByteToBinary(pixel_byte_b);
  103.  
  104. pixel_binary_r = "000000" + pixel_binary_r.Substring(6, 2);
  105. pixel_binary_g = "000000" + pixel_binary_g.Substring(6, 2);
  106. pixel_binary_b = "000000" + pixel_binary_b.Substring(6, 2);
  107.  
  108. pixel_byte_r = Generic.BinaryToByte(pixel_binary_r);
  109. pixel_byte_g = Generic.BinaryToByte(pixel_binary_g);
  110. pixel_byte_b = Generic.BinaryToByte(pixel_binary_b);
  111.  
  112. pixel_colour = System.Drawing.Color.FromArgb(pixel_byte_r, pixel_byte_g, pixel_byte_b);
  113. image_bitmap.SetPixel(image_width, image_height, pixel_colour);
  114. }
  115. }
  116. image_bitmap.Save(output);
  117. }
  118.  
  119. public static System.Drawing.Bitmap CreateNonIndexedImage(System.Drawing.Image src)
  120. {
  121. System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  122.  
  123. using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(newBmp))
  124. {
  125. gfx.DrawImage(src, 0, 0);
  126. }
  127.  
  128. return newBmp;
  129. }
  130.  
  131. public static string ByteToBinary(int b)
  132. {
  133. return Convert.ToString(b, 2).PadLeft(8, '0');
  134. }
  135.  
  136. public static int BinaryToByte(string binary)
  137. {
  138. int r = Convert.ToInt32(binary, 2);
  139. return r;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement