java - embedding and extracting data in an image -
i wrote code embeds , extracts text in image. despite best attempts not able understand wrong in code due extraction not successful.looking help on same. here code
public class embedandextract { //embedding sequence bufferedimage embed(bufferedimage img, string s) { int pixel[] = img.getrgb(0, 0, img.getwidth(), img.getheight(), null, 0, img.getwidth()); //the manipulated pixels saved in newpixel[] int[] newpixel = arrays.copyof(pixel, pixel.length); int len = s.length(); int q = 0; //each string embedded prefixed 4 chars contain length of string // string "abc" s1="0003abc" //here first 4 chars show length of string (int = 0; < 4; i++) { if (len % 10 == 0) { break; } else { len = len / 10; q++; } } string s1 = ""; (int = 0; < 4 - q; i++) { s1 += 0; } s1 += s.length(); s1 += s; // convert s1 byte array byte[] b = s1.getbytes(); (int = 0; < b.length; i++) { system.out.println("" + (char) b[i]); } //change value of newpixel[] per string int count = 0; (int = 0; < b.length; i++) { byte current_byte = b[i]; (int j = 7; j >= 0; j--) { int lsb = (current_byte >> j) & 1; newpixel[count] = (pixel[count] & 0xfffffffe) + lsb; system.out.println(lsb + ":(" + pixel[count] + "," + newpixel[count] + ")"); count++; } } //add newpixel[] bufferedimage , homecoming bufferedimage nimg = new bufferedimage(img.getwidth(), img.getheight(), bufferedimage.type_4byte_abgr); nimg.setrgb(0, 0, nimg.getwidth(), nimg.getheight(), newpixel, 0, nimg.getwidth()); homecoming nimg; } //extraction sequence string extract(bufferedimage img) { //read pixel of image int newpixel[] = img.getrgb(0, 0, img.getwidth(), img.getheight(), null, 0, img.getwidth()); //extract length first 32 pixel values i.e constitute 4 bytes string qw = ""; (int = 0; < 32; i++) { qw += (newpixel[i] & 0x00000001); } //convert length integer , save in total int n1, n2, n3, n4, total; n1 = integer.parseint(qw.substring(0, 8), 2) - 48; n2 = integer.parseint(qw.substring(8, 16), 2) - 48; n3 = integer.parseint(qw.substring(16, 24), 2) - 48; n4 = integer.parseint(qw.substring(24, 32), 2) - 48; total = n1 * 1000 + n2 * 100 + n3 * 10 + n4; system.out.println("" + total); //extract string image , reurn string string secret = ""; int bit = 0; (int = 0; < 4 + total; i++) { int ascii = 0; (int j = 7; j >= 0; j--) { ascii += (newpixel[bit] & 1) << j; bit++; } secret += (char) ascii; } homecoming secret; } }
the first 32 pixel values contains length of info in embedding sequence , extracting sequence coming different don't know how. if 1 can resolve errors wouldbe grateful.
java rgb bufferedimage steganography
No comments:
Post a Comment