Advertisement
EaterSun

Embedded Automation LSB

Nov 27th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | Cybersecurity | 0 0
  1. from PIL import Image
  2.  
  3. def embed_label(image_path, label, output_path):
  4.     img = Image.open(image_path)
  5.     binary_label = ''.join(format(ord(char), '08b') for char in label) + '11111110'  
  6.     data = img.getdata()
  7.  
  8.     new_data = []
  9.     bit_index = 0
  10.     for pixel in data:
  11.         new_pixel = list(pixel)
  12.         for i in range(len(new_pixel)):
  13.             if bit_index < len(binary_label):
  14.                 new_pixel[i] = (new_pixel[i] & ~1) | int(binary_label[bit_index])
  15.                 bit_index += 1
  16.         new_data.append(tuple(new_pixel))
  17.  
  18.     img.putdata(new_data)
  19.     img.save(output_path)
  20.     print("Label berhasil disisipkan!")
  21.  
  22. embed_label("IPB.png", "SVIPB", "output1.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement