java - I can't fix the decode after changing some lines -
now i've changed decoding , encoding based on answer here, cant datacomparison
work. tried applying decoding lines pointed out fail encoded data in picture.
here original datacomparison
worked using original encoding/decoding code.
datacomparison
decoding decodes 2 files (that created steganography) , compares them. gui.appendstatus()
calls below prompts data has been extracted.
for(int = 0; < height; i++){ for(int j = 0; j < width; j++){ color c = new color(image.getrgb(j, i)); color c2 = new color(image2.getrgb(j, i)); lossydata += getlsb(integertobinary((int)(c.getred())),lsb); lossydata += getlsb(integertobinary((int)(c.getgreen())),lsb); lossydata += getlsb(integertobinary((int)(c.getblue())),lsb); losslessdata += getlsb(integertobinary((int)(c2.getred())),lsb); losslessdata += getlsb(integertobinary((int)(c2.getgreen())),lsb); losslessdata += getlsb(integertobinary((int)(c2.getblue())),lsb); clossydata[i][j][0] = c.getred(); clossydata[i][j][1] = c.getgreen(); clossydata[i][j][2] = c.getblue(); closslessdata[i][j][0] = c2.getred(); closslessdata[i][j][1] = c2.getgreen(); closslessdata[i][j][2] = c2.getblue(); if(limit >= 8 * lsb){ break; } } } int counter = 0; while(counter * 8 < losslessdata.length()){ int index = counter * 8; string str = lossydata.substring(index, index + 8); string str2 = losslessdata.substring(index, index + 8); lydata += str; lsdata += str2; if(!str2.equals("00000000")){ lossymessage += new character((char)integer.parseint(str, 2)).tostring(); losslessmessage += new character((char)integer.parseint(str2, 2)).tostring(); counter++; } else{ lydata = lydata.substring(0,lydata.length()-8); lsdata = lsdata.substring(0,lsdata.length()-8); break; } } int = 0, lostbits = 0; while(i < lydata.length()){ if(lydata.charat(i) != lsdata.charat(i)){ lostbits++; } i++; } gui.appendstatus("data decoded (lossless):\n\"" + lsdata + "\"."); gui.appendstatus("data decoded (lossy):\n\"" + lydata + "\"."); gui.appendstatus("number of lsb: " + lsb); gui.appendstatus("number of bits (hidden message): " + counter * 8); gui.appendstatus("number of lost bits (hidden message): " + lostbits); float z = ((lostbits*100)/(counter*8)); string percentage = string.format("%.04f", z); gui.appendstatus("percentage of lost bits (hidden message): " + percentage + "%"); gui.appendstatus("message decoded (lossless): \"" + losslessmessage + "\"."); gui.appendstatus("message decoded (lossy): \"" + lossymessage + "\"."); gui.appendstatus("number of characters: " + counter); int counterr = 0, counterg = 0, counterb = 0; for(int p = 0; p < height; p++){ for(int q = 0; q < width; q++){ if(closslessdata[p][q][0] != clossydata[p][q][0]){ counterr++; } else if(closslessdata[p][q][1] != clossydata[p][q][1]){ counterg++; } else if(closslessdata[p][q][2] != clossydata[p][q][2]){ counterb++; } } } gui.appendstatus("total rgb values: " + width * height * 3); gui.appendstatus("altered red values: " + counterr); gui.appendstatus("altered green values: " + counterg); gui.appendstatus("altered blue values: " + counterb); gui.appendstatus("total altered values: " + (counterr + counterg + counterb)); z = ((counterr + counterg + counterb)*10000)/(width * height * 3); percentage = string.format("%.02f", z/100); gui.appendstatus("percentage altered values: " + percentage + "%");
the code above working based on original encoding/decoding algorithm. 1 doesnt stop loop. tried editing code , applying new decoding algorithm cant make work.
what should done make work?
edit
i removed hideous codes , included datacomparison
. i've removed available @ link (my previous question)
here's datacomparison
block changed based on reti43's answer doesnt work new encoding. cant decode encoded message here using datacomparison
decoding1: for(int = 0; < height; i++){ for(int j = 0; j < width; j++){ color c = new color(image.getrgb(j, i)); lossydata += getlsb(integertobinary((int)(c.getred())),lsb); if(limit >= 8) break decoding1; lossydata += getlsb(integertobinary((int)(c.getgreen())),lsb); if(limit >= 8) break decoding1; lossydata += getlsb(integertobinary((int)(c.getblue())),lsb); if(limit >= 8) break decoding1; } } decoding2: for(int = 0; < height; i++){ for(int j = 0; j < width; j++){ color c = new color(image.getrgb(j, i)); losslessdata += getlsb(integertobinary((int)(c.getred())),lsb); if(limit >= 8) break decoding2; losslessdata += getlsb(integertobinary((int)(c.getgreen())),lsb); if(limit >= 8) break decoding2; losslessdata += getlsb(integertobinary((int)(c.getblue())),lsb); if(limit >= 8) break decoding2; } } decoding3: for(int = 0; < height; i++){ for(int j = 0; j < width; j++){ color c = new color(image.getrgb(j, i)); clossydata[i][j][0] = c.getred(); if(limit >= 8) break decoding3; clossydata[i][j][1] = c.getgreen(); if(limit >= 8) break decoding3; clossydata[i][j][2] = c.getblue(); if(limit >= 8) break decoding3; } } decoding4: for(int = 0; < height; i++){ for(int j = 0; j < width; j++){ color c = new color(image.getrgb(j, i)); closslessdata[i][j][0] = c.getred(); if(limit >= 8) break decoding4; closslessdata[i][j][1] = c.getgreen(); if(limit >= 8) break decoding4; closslessdata[i][j][2] = c.getblue(); if(limit >= 8) break decoding4; } } (int index = 0; index < lossydata.length()/8; index++) { string str = lossydata.substring(8*index, 8*index+8); lydata += str; lossymessage += new character((char)integer.parseint(str, 2)).tostring(); } (int index = 0; index < losslessdata.length()/8; index++) { string str = losslessdata.substring(8*index, 8*index+8); lsdata += str; losslessmessage += new character((char)integer.parseint(str, 2)).tostring(); } int = 0, lostbits = 0; while(i < lydata.length()){ if(lydata.charat(i) != lsdata.charat(i)){ lostbits++; } i++; } int counter = losslessmessage.length(); gui.appendstatus2("data decoded (lossless):\n\"" + losslessdata + "\"."); gui.appendstatus2("data decoded (lossy):\n\"" + lydata + "\"."); gui.appendstatus2("number of lsb: " + lsb); gui.appendstatus2("number of bits (hidden message): " + counter * 8); gui.appendstatus2("number of lost bits (hidden message): " + lostbits); float z = ((lostbits*100)/(counter*8)); string percentage = string.format("%.04f", z); gui.appendstatus2("percentage of lost bits (hidden message): " + percentage + "%"); gui.appendstatus2("message decoded (lossless): \"" + losslessmessage + "\"."); gui.appendstatus2("message decoded (lossy): \"" + lossymessage + "\"."); gui.appendstatus2("number of characters: " + counter); int counterr = 0, counterg = 0, counterb = 0; for(int p = 0; p < height; p++){ for(int q = 0; q < width; q++){ if(closslessdata[p][q][0] != clossydata[p][q][0]){ counterr++; } else if(closslessdata[p][q][1] != clossydata[p][q][1]){ counterg++; } else if(closslessdata[p][q][2] != clossydata[p][q][2]){ counterb++; } } } gui.appendstatus2("total rgb values: " + width * height * 3); gui.appendstatus2("altered red values: " + counterr); gui.appendstatus2("altered green values: " + counterg); gui.appendstatus2("altered blue values: " + counterb); gui.appendstatus2("total altered values: " + (counterr + counterg + counterb)); z = ((counterr + counterg + counterb)*10000)/(width * height * 3); percentage = string.format("%.02f", z/100); gui.appendstatus2("percentage altered values: " + percentage + "%");
image2
not used. both 2 files used image
there no difference, , reset limit after every loop made trick work
Comments
Post a Comment