0

I need to read in a message from the user, iterate across each bit of the message and overwrite the least significant image bit with each message bit.

I currently have a program that iterates over each image pixel and just rewrites out the image.

So how can i read the least significant image bit and how can i get each message bit.

This is for a grey scale image using python 3.x

from PIL import Image

import numpy as np
import bitget
import scipy.misc as smp

im = Image.open("catBlack.png") #Can be many different formats.
pix = im.load()
print (im.size )#Get the width and hight of the image for iterating over
print (pix[1,1]) #Get the RGBA Value of the a pixel of an image
#pix[x,y] = value # Set the RGBA Value of the image (tup


data = np.zeros( (im.size[0],im.size[1],2), dtype=np.uint8 )

for i in range (im.size[0]):
    for j in range (im.size[1]):
        print (i,j)
        data[i,j] = pix[i,j]

im = Image.fromarray(data)
im.save("GreyCat.png")

Also , how would i decode out this message

Cheers for the help

bpb101
  • 971
  • 1
  • 9
  • 18
  • I vote to close as too broad because you're asking about the whole process of steganogaphy. If you understand the encoding steps, decoding should be the reverse of that. And encoding can be broken down to smaller questions, which you've asked. However, they're fairly trivial, [1](https://stackoverflow.com/questions/18815820/convert-string-to-binary-in-python) and [2](https://stackoverflow.com/questions/4822130/reading-least-significant-bits-in-python). – Reti43 Dec 09 '16 at 02:17
  • Im question the topic as a whole , as i dont know where to start with it? How do to go about it? how do i do the replacement. is it you get the pixel convert that to bits, and place the asci bit value in the place of the lsb of the image pixel. Does each string character take up multi bits. How to i signal the end of the text and the start of the text – bpb101 Dec 09 '16 at 02:23
  • you might wanna consider existing [steganography_tools](https://en.wikipedia.org/wiki/Steganography_tools) – Skycc Dec 09 '16 at 09:44

1 Answers1

2

After reading the message you can convert it into ascii code (ascii range exists between 0 and 127) i.e you will need max. 7 bits to represent the letter

Gray scale can have value from 0 to 255 and each pixel has 8 bits so you can use 2 last bits of 4 pixels to represent one word.

e.g You want to transmit hi

ascii code of h - 73 binary of 73 - 1001001 ascii code of i - 74 ascii code of i -1001010

  • now you will iterate through each pixel like you mentioned
  • read the color value of pixel convert it into binary

suppose color value is

1111111 for first pixel
0101010 for second
1100110 for third
1111111 for fourth
0001111 for fifth
1011111 for sixth
1100110 for seventh
1110001 for eighth
1111111 for ninth
1010101 for tenth

first we have to transmit h (01001001) so we will change last two bits of 4 pixels new values of color will be something like this

1111101 for first pixel
0101000 for second
1100110 for third
1111101 for fourth

now for i (01001010) values will be like

0001101 for fifth
1011100 for sixth
1100110 for seventh
1110010 for eighth

now we will change remaining pixels last bits to all zeros
1111100 for ninth
1010100 for tenth

Ash Ishh
  • 551
  • 5
  • 15
  • Super. really well explained. One question is, for the rest of the pixels Do you change the last 2 bits to 00 or would you keep them as is? – bpb101 Dec 09 '16 at 02:32
  • you should change them to zeros that will help to identify end of message (at the time of decoding value of ascii 0 is null)..if you will not make them zeros at the time of decoding message it will try to decode the remaining bits and you will get unwanted message at the end.. – Ash Ishh Dec 09 '16 at 13:01