Advertisement
Guest User

Untitled

a guest
May 1st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public static string DLSB(Bitmap bmp)
  2. {
  3. string ExtractedText = "";
  4. List<int> IDBits = new List<int>();
  5. List<int> MsgBits = new List<int>();
  6. string ID = "";
  7. int MarqueSize = 0;
  8. bool IDFound = false;
  9. int ColorIndex = 0, Counter = 0, charValue = 0;
  10.  
  11. for (int x = 0; x < bmp.Width; x++)
  12. {
  13. for (int y = 0; y < bmp.Height; y++)
  14. {
  15. Color pixel = bmp.GetPixel(x, y);
  16.  
  17. for (int n = 0; n < 3; n++)
  18. {
  19. if (ColorIndex % 3 == 0)
  20. {
  21. charValue = charValue * 2 + pixel.R % 2;
  22. }
  23. else if (ColorIndex % 3 == 1)
  24. {
  25. charValue = charValue * 2 + pixel.G % 2;
  26. }
  27. else if (ColorIndex % 3 == 2)
  28. {
  29. charValue = charValue * 2 + pixel.B % 2;
  30. }
  31.  
  32. ColorIndex++;
  33. Counter++;
  34.  
  35. if (IDFound) MsgBits.Add(charValue % 2);
  36. else IDBits.Add(charValue % 2);
  37.  
  38. if (Counter == 8)
  39. {
  40. if (!IDFound && charValue == 0)
  41. {
  42. IDFound = true;
  43. ID = BitToString(IDBits);
  44. MarqueSize = Convert.ToInt16(ID.Split('-')[2]) * 8;
  45. Console.WriteLine("ID Found : " + ID);
  46. }
  47. else if (IDFound && MsgBits.Count >= MarqueSize) goto ExtractionDone;
  48.  
  49. charValue = 0;
  50. Counter = 0;
  51. }
  52.  
  53. } // End For loop pixel colors
  54. } // end for y
  55. } // end for x
  56.  
  57. ExtractionDone:
  58. Console.WriteLine("ExtractionDone");
  59. ExtractedText = BitToString(MsgBits);
  60. return ExtractedText;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement