java - Hiding message in JPG image -
i trying hide in image it's working fine .bmp & .png when write image jpg , try retrieve hidden message not working. procedure, first read image in format (bmp, gif, jpg,png) write message hide , save can again read , extract message. when save bmp or png works fine when saving jpg , try extract message doesn't work.
imageio.write(bimg, "png", outputfile);//working imageio.write(bimg, "png", outputfile);//not working what should make work jpeg?
note: reading every pixel 4 bit integer argb value , changing lsb of r,g,b hide message.
public void stegnography(bufferedimage bimg,string msg,string filename) { int w=bimg.getwidth(); int h=bimg.getheight(); //*************************************** // string msg="hide message:)"; system.out.println("message="+msg+" length="+msg.length()); //*************************************** if(msg.length()>255 ) { jlabel3.settext("message large 255 characters"); } else if( msg.length()*11 >w*h) { jlabel3.settext("image small"); } else{ //------------------------------------------- byte[] msgbytes= msg.getbytes(); int msglendecode= (bimg.getrgb(0,0)>>8)<<8; msglendecode |= msg.length(); bimg.setrgb(0, 0,msglendecode );//hidig msg length @ first position //system.out.println("\npixel @ position (0,0) "); // bitpattern(bimg.getrgb(0,0) ); for(int i=1,msgpos=0,row=0,j=0; row<h ;row++ ) { for(int col=0;col<w && j<msgbytes.length ;col++,i++ ) { if (i%11==0) { int rgb = bimg.getrgb(col,row); int a=((rgb >> 24) & 0xff); int r = (((rgb >> 16) & 0xff)>>3)<<3; r=r|(msgbytes[msgpos]>>5); int g = (((rgb >> 8) & 0xff)>>3)<<3; g=g|((msgbytes[msgpos]>>2)& 7); int b = ((rgb & 0xff)>>2)<<2; b=b|(msgbytes[msgpos]&0x3); rgb=0; rgb=(rgb|(a<<24)); rgb=(rgb|(r<<16)); rgb=(rgb|(g<<8)); rgb=(rgb|b); bimg.setrgb(col,row,rgb); msgpos++; j++; //bitpattern(bimg.getrgb(col,row)); } }//for 2 }//for 1 imageicon image = new imageicon(bimg); jlabel3.seticon(image); try { // file outputfile = new file("c:/users/yathestha/documents/"+filename); file outputfile = new file("c:/users/yathestha/documents/outpng.png"); imageio.write(bimg, "png", outputfile); } catch (ioexception e) { system.out.println("error in saving image "); } //------------------------------------------------- }//else // decoding part---------------------------------------------------------------------- } /////////////////////////////////////////////////////////////////////// private void decodestegnography(bufferedimage bimg) { system.out.println("in decode"); int w=bimg.getwidth(),h=bimg.getheight(); bitpattern(bimg.getrgb(0, 0)); int msglength=(bimg.getrgb(0, 0)&0xff); bitpattern(msglength); system.out.println("message length="+msglength); jtextfield1.settext(""); for(int row=0,j=0,i=1; row<h ;row++ ) { for(int col=0;col<w && j<msglength ;col++ ,i++) { if (i%11==0) { int result=bimg.getrgb(col,row); int charatpos = (((result >> 16) & 0x7) << 5); charatpos |= (((result >> 8) & 0x7) << 2); charatpos |= ((result & 0x3)); jtextfield1.settext(jtextfield1.gettext()+ (char)charatpos); j++; } } } system.out.println("decoding done"); }//function
for jpeg steganography either save result lossless jpeg, or use different stegographic method. 1 know fiddling discrete cosine transform coefficients (dct). however, need aware of rounding errors , such retrieval of secret lossy.
i don't favour dct , haven't looked lot, here paper 2007 claims jpeg lossless steganography. warned algorithm more complex casual lsb substitution in spatial domain. hiding data in frequency domain means lower hiding capacity , don't know whether serve you. if interested , can't access paper, can sort out privately.
Comments
Post a Comment