EaterSun

Embedded Offset LSB

Nov 27th, 2024 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | Cybersecurity | 0 0
  1. def message_to_binary(message):
  2.     return ''.join(format(ord(char), '08b') for char in message)
  3.  
  4. def embed_message(img_file, output_file, message, offset=55920):
  5.     with open(img_file, 'rb') as f:
  6.         img_bytes = bytearray(f.read())
  7.     message_binary = message_to_binary(message) + '11111111'
  8.     if len(message_binary) > len(img_bytes) - offset:
  9.         raise ValueError("Pesan terlalu besar untuk disisipkan ke dalam gambar!")
  10.  
  11.     for i, bit in enumerate(message_binary):
  12.         byte_index = offset + i
  13.         img_bytes[byte_index] = (img_bytes[byte_index] & 0b11111110) | int(bit)
  14.  
  15.     with open(output_file, 'wb') as f:
  16.         f.write(img_bytes)
  17.  
  18.     print(f"Pesan berhasil disisipkan ke dalam file {output_file}.")
  19.  
  20. embed_message("IPB.png", "output3.png", "SVIPB")
  21.  
Add Comment
Please, Sign In to add comment