Results 1 to 20 of 23
- 04-05-2009, 02:22 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
[SOLVED] cryptography and steganography - URGENT HELP NEEDED PLEASEEE
hello all
I and my team mate have been doing my project in steganography for college work
All we wanted to do was to encrypt some text and store it in an image. then extract the encrypted text and decrypt it.
for cryptography -we used RSA algorithm
for steganography - we used LSB algorithm
I have implemented steganography algortihm. It works good.
My friend has implemented rsa algortihm. It also works fine
But the issue is when we are integrating both of them, we are getting errors.
Dont know why??:confused::confused::confused::confused::conf used:
The issue is we are storing and extracting the file of encrypted data. We are getting THE SAME FILE WHEN WE ARE EXTRACTING IT FROM THE IMAGE.
BUT when we are decrypting it, we are not getting the proper result and are getting some different symbols. I think non-ascii characters. why is this happening??
That is if we decrypt the output of encryption directly, we are getting the result. but when we are applying steganography and getting the SAME encrypted file and decrypting it, we are getting these different symbols.
Why is this happening??
Anyone got any ideas???
I have to resolve this and submit it in two days!!
Pleaseeeeeeeeee help me out!!
Any kind of help is appreciated!!
Thank you.with warm regards,
Sruthi :)
- 04-05-2009, 03:47 PM #2
If you have two copies of the same thing and decrypt it using the same algorithm and keys you can't not get the same result, unless you've done something wrong. We're going to have to see some source code.
- 04-05-2009, 08:02 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
@OrangeDog
Thanks for your reply! :)
On More careful inspection I've found out the following :
the mistake is not in the encryption and decryption techniques.
It is in the steganography technique.
I manipulate the lsb values of a pixel and store it as a image file.
Now I access the pixel values of this stored image to extract my message.
After seeing the pixel values, what I've observed is that for some pixels, the values with which I have constructed the STEGO image are different from those values when I am accessing those same pixels of the STEGO image for extracting my data, so I am getting errors! :(
I am using Bitmap images because they are lossless compression.
I am using Pixelgrabber to grab the pixels into an integer array.
I am using the following code to construct the image from the array
Why is this happening???Java Code:stego_img = new BufferedImage(org_width,org_height,type); stego_img.setRGB (0, 0, org_width, org_height, stegoimg_pixelarr, 0, org_width);
Any help is appreciated.
Thank youwith warm regards,
Sruthi :)
- 04-05-2009, 09:13 PM #4
What happens to the buffered image after this? How are you reading back the values?
I'm unclear as to exactly what is different. Try rephrasing the line ending in :(
- 04-06-2009, 04:32 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
Thanks for the reply! :)
I am storing the buffered image as a file in the system.
And I am accessing the pixels again using PixelGrabber classwith warm regards,
Sruthi :)
- 04-06-2009, 04:43 AM #6
Sorry, I meant code-wise. What is the code that does this?
It's easier if you just post here instead of sending private messages, then everyone can help.
- 04-06-2009, 04:52 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
here is the code for stego class
Java Code:import java.util.*; import java.io.*; import java.util.Random; import java.lang.*; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.*; class pseudo_random_generator { int n; int limit; int random_no_arr[]; //Constructor public pseudo_random_generator(int a,int l) { n=a; limit=l; random_no_arr=new int[n+1]; } public void generate_random_no() { long s=n; int j; Random aRandom = new Random(); //declare a new instance of the Random class aRandom.setSeed(s); //set the seed of aRandom for(j=0;j<n;j++) //storing random numbers random_no_arr[j] = aRandom.nextInt(limit); } } public class stego{ Image org; int type; int org_width; int org_height; int org_pixelarr[]; int stegoimg_pixelarr[]; BufferedImage stego_img; static int m; int l; int n; String path; String ext; //Constructor public stego(String s, int b, String m1) { try { File f = new File(s); int x = s.lastIndexOf("."); ext = s.substring(x+1); BufferedImage b_org = ImageIO.read(f); type = b_org.getType(); org=(Image)b_org; org_width=org.getWidth(null); org_height=org.getHeight(null); org_pixelarr = new int[org_width * org_height]; stegoimg_pixelarr = new int[org_width * org_height]; try{ PixelGrabber grabber = new PixelGrabber(org, 0, 0, org_width, org_height, org_pixelarr,0,org_width); grabber.grabPixels(); } catch (InterruptedException ie) { } stegoimg_pixelarr = (int [])org_pixelarr; stego_img=null; m=b; path=m1; File fi = new File(path); Long x1 = new Long(fi.length()); l=x1.intValue(); n=l/m; //System.out.println("n value: "+n); //what if n values is in decimal??- then u have to pad extra bits!! }catch(IOException en) { en.printStackTrace(); System.out.println("Error while initialising the constructor of stego class! "+en); } } public static int lsb(int i) { String a=Integer.toBinaryString(i); String b=a.substring(a.length()-m); int lsbval=Integer.parseInt(b,2); return lsbval; } public static int power(int x, int y) { int res=1; for(int i=0;i<y;i++) res=res*x; return res; } void construct_stego_image() { try{ int i,j=0,t1,t2; int x[]=new int[n+1]; int e[]=new int[n+1]; pseudo_random_generator g = new pseudo_random_generator(n,org_width*org_height); g.generate_random_no(); /*System.out.println("The random numbers are:"); for(i=0;i<=n;i++) { System.out.println(g.random_no_arr[i]); } System.out.println("original pixel values are:");*/ Intarraytofile.toFile("C:/org r values.txt",g.random_no_arr,n+1); for(i=0;i<=n;i++) { x[i]=org_pixelarr[g.random_no_arr[i]]; // System.out.println(x[i]); } Intarraytofile.toFile("C:/org x values.txt",x,n+1); File f=new File(path); FileReader fr=new FileReader(f); BufferedReader br=new BufferedReader(fr); int c1; char c; String temp = new String(); String t=new String(); while((c1=br.read())!= -1) { c=(char)c1; t=Character.toString(c); temp=temp.concat(t); } //System.out.println("message is :"+temp); //System.out.println("e[i]values"); for(i=1;i<=n;i++) { e[i]=Integer.parseInt(temp.substring(j,j+m),2); j=j+m; // System.out.println("e["+i+"]: "+e[i]); } Intarraytofile.toFile("C:/e values.txt",e,n+1); for(i=1;i<=n;i++) { t1=lsb(x[i-1]); t2=lsb(x[i]); x[i]= x[i]+e[i]-((t1+t2)%(power(2,m))); } //System.out.println("The modified pixel values are:"); for(i=0;i<=n;i++) { // System.out.println(x[i]); stegoimg_pixelarr[g.random_no_arr[i]]=x[i]; } stego_img = new BufferedImage(org_width,org_height,type); stego_img.setRGB (0, 0, org_width, org_height, stegoimg_pixelarr, 0, org_width); Intarraytofile.toFile("C:/modified x values.txt",x,n+1); }catch(IOException e){ System.out.println("IOError, stego image construction");} } void store_stego_image(String s) { try{ File fil = new File(s); ImageIO.write(stego_img, ext, fil); }catch(Exception en) { en.printStackTrace(); System.out.println("Error! "+en); } } public static void main(String args[]) { try { String src,dest,text,msg; String t="C:/binary.txt"; int b; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the no.of lsbs to be selected m:"); b=Integer.parseInt(br.readLine()); System.out.println("enter the path of text file:"); text=br.readLine(); System.out.println("Please enter source path of a valid image:"); src=br.readLine(); System.out.println("Please enter destination path of a stego image:"); dest=br.readLine(); Fileconversion.converttobinary(text,t); stego st=new stego(src,b,t); st.construct_stego_image(); st.store_stego_image(dest); System.out.println("The key is: "+st.n); }catch(IOException en) { en.printStackTrace(); System.out.println("Error in main! "+en); } } }
The code for extracting the message is:
Java Code:import java.util.*; import java.io.*; import java.util.Random; import java.lang.*; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.*; class pseudo_random_generator { int n; int limit; int random_no_arr[]; //Constructor public pseudo_random_generator(int a,int l) { n=a; limit=l; random_no_arr=new int[n+1]; } public void generate_random_no() { long s=n; int j; Random aRandom = new Random(); //declare a new instance of the Random class aRandom.setSeed(s); //set the seed of aRandom for(j=0;j<n;j++) //storing random numbers random_no_arr[j] = aRandom.nextInt(limit); } } public class inverse_stego{ Image stego_img; int stego_img_width; int stego_img_height; int stego_img_pixelarr[]; static int m; int l; int n; String msg; //Constructor public inverse_stego(String s, int b, int a) { try { File f = new File(s); BufferedImage b_stego_img = ImageIO.read(f); stego_img=(Image)b_stego_img; stego_img_width=stego_img.getWidth(null); stego_img_height=stego_img.getHeight(null); stego_img_pixelarr = new int[stego_img_width * stego_img_height]; try{ PixelGrabber grabber = new PixelGrabber(stego_img, 0, 0, stego_img_width, stego_img_height, stego_img_pixelarr,0,stego_img_width); grabber.grabPixels(); } catch (InterruptedException ie) { } m=b; n=a; msg=null; l=n*m; }catch(IOException en) { en.printStackTrace(); System.out.println("Error while initialising the constructor of inverse_stego class! "+en); } } public static int lsb(int i) { String a=Integer.toBinaryString(i); String b=a.substring(a.length()-m); int lsbval=Integer.parseInt(b,2); return lsbval; } public static int power(int x, int y) { int res=1; for(int i=0;i<y;i++) res=res*x; return res; } void construct_message() { String a=new String(); String b=new String(); int i,j=0,t1,t2; int x[]=new int[n+1]; int e[]=new int[n+1]; pseudo_random_generator g = new pseudo_random_generator(n,stego_img_width*stego_img_height); g.generate_random_no(); /* System.out.println("The random numbers are:"); for(i=0;i<=n;i++) { System.out.println(g.random_no_arr[i]); } System.out.println("original pixel values are:");*/ Intarraytofile.toFile("C:/stego r values.txt",g.random_no_arr,n+1); for(i=0;i<=n;i++) { x[i]=stego_img_pixelarr[g.random_no_arr[i]]; //System.out.println(x[i]); } Intarraytofile.toFile("C:/stego pixelvalues.txt",x,n+1); for(i=1;i<=n;i++) { t1=lsb(x[i-1]); t2=lsb(x[i]); e[i]=(t1+t2)%(power(2,m)); } Intarraytofile.toFile("C:/stego e values.txt",e,n+1); for(i=1;i<=n;i++) { String t=new String(); // System.out.println(e[i]); a=Integer.toBinaryString(e[i]); if(a.length()<m) { for(int k=0;k<m-a.length();k++) t=t.concat("0"); a=t.concat(a); } b=b.concat(a); } msg=b; // System.out.println("The message is : "+ msg); } //--------------------------------------------------------------------------------------------------------------- public static void main(String args[]) { try { String src,dest,temp="C:/temp.txt"; int a,b; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter the no.of lsbs to be selected m:"); b=Integer.parseInt(br.readLine()); System.out.println("enter key:"); a=Integer.parseInt(br.readLine()); System.out.println("Please enter source path of stego image:"); src=br.readLine(); inverse_stego ist=new inverse_stego(src,b,a); ist.construct_message(); System.out.println("Please enter destination path of text file:"); dest=br.readLine(); Writer output = null; File file = new File(temp); output = new BufferedWriter(new FileWriter(file)); output.write(ist.msg); output.close(); Fileconversion.converttofile(temp,dest); System.out.println("The file has been extracted!!"); }catch(IOException en) { en.printStackTrace(); System.out.println("Error in main! "+en); } } }
The Intarraytofile just writes an Integer array to file - I've just added it so that I could see the pixel values
The Fileconversion class has two methods:
one to convert the contents of a file into binary - converttobinary method
other to convert binary data to normal text and to write into file -converttofile method
Thank youwith warm regards,
Sruthi :)
- 04-06-2009, 04:55 AM #8
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
@OrangeDog
If you have noticed, I've been posting here also the same stuff which I've been messaging you only in the hope that a message would be seen instantaneously, but if you are busy seeing other threads, you may not notice my reply in the thread. And that too because you are online. I am sorry if I've annoyed you.
Just in a panicky mode because of the deadlines. thats it!!with warm regards,
Sruthi :)
- 04-06-2009, 03:31 PM #9
Can you pin down which of these methods isn't doing what you expect?
(using binary operators is better than string manipulation for getting the lsb e.g. lsb = 0x07 & orig would get the lowest 3 bits)
- 04-06-2009, 09:34 PM #10
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
I exactly dont know which method is not working!!
IN the stego class, after storing the stego image in the system, when i am grabbing the pixels from that, i am not getting correct values for some pixels!!with warm regards,
Sruthi :)
- 04-07-2009, 07:55 PM #11
Can you store data in a single pixel and extract it successfully?
Can you store and extract data in a whole picture without saving it?
Is the image you are saving what you expect?
When you load the image, is it the same image as you saved?
Essentially you have done something wrong and there is too much code for us to be able to see what it is. You're going to have to work out what exactly doesn't work before you can fix it.
- 04-07-2009, 10:25 PM #12
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
Are you sure you're not saving the image in a lossy format?
Neil Coffey
Javamex - Java tutorials and performance info
- 04-08-2009, 03:48 AM #13
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
Thanks for the reply
@neilcoffey
Well i am saving the bitmap images, so it is not lossy but lossless compression
@OrangeDog
I can store the data in a single pixel and extract it successfully.
IF the data i am storing in an image is less,say around 50-200 characters, then i am getting the correct output i.e. I am able to extract the correct data.
But if the data to be embedded is more say around 500 characters, then i am unable to retrieve some characters of the data.
Since I am encrypting the data before hiding it, the data length is becoming more, and while extracting i am getting errors, which i am unable to decrypt properlywith warm regards,
Sruthi :)
- 04-08-2009, 03:55 AM #14
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
I would like to know the way I am storing an image and retrieving the pixels is correct or not, or could there be any mistake by doing this way??
Here is the code for extracting the pixels:
Here is the code that is used to store the imageJava Code:try{ PixelGrabber grabber = new PixelGrabber(org, 0, 0, org_width, org_height, org_pixelarr,0,org_width); grabber.grabPixels(); } catch (InterruptedException ie) { }
Java Code:stego_img = new BufferedImage(org_width,org_height,type); stego_img.setRGB (0, 0, org_width, org_height, stegoimg_pixelarr, 0, org_width); File fil = new File(s); ImageIO.write(stego_img, ext, fil);
with warm regards,
Sruthi :)
- 04-08-2009, 06:44 PM #15
It could be that with longer messages you end up storing in the same pixels twice. Have you got any checks that make sure you don't get any repeats from your random number generator?
- 04-08-2009, 07:46 PM #16
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
yes, there cant be any repeats during generating the random numbers. using Random class in java for that!!
After storing the stego image in the system, when i am grabbing the pixels from that, i am not getting correct values for some pixels!!
Why is this happening??????????????????????
Any one plss help
Any help is appreciatedwith warm regards,
Sruthi :)
- 04-08-2009, 09:28 PM #17
Just looked again at your code. Yes, you can get repeated random numbers from Random, especially if you are asking for integers in a fixed limit. If it gave you only one of each int it wouldn't be very random and then you'd run out.
Last edited by OrangeDog; 04-08-2009 at 09:56 PM.
- 04-09-2009, 04:15 AM #18
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
hmmm
Thanks for the reply!!
I will check it out surely!!with warm regards,
Sruthi :)
- 04-09-2009, 04:44 AM #19
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
@OrangeDog
Thank you so much for pointing out the error!! :) Never though that the generation of pseudo random numbers was an issue!! I was always bent on coding only!!
I would like to know if there is any predefined class for generating non-repetitive pseudo-random numbers in java or I should write seperate code for it?
Can any one give me any suggestions??
Any help is appreciated!!
Thank you!!with warm regards,
Sruthi :)
- 04-09-2009, 03:51 PM #20
Member
- Join Date
- Feb 2009
- Posts
- 32
- Rep Power
- 0
Thank you all for helping me solve the problem.
I have generated non-repetitive pseudo-random numbers by using BitSet class to check if that number has been already generated and thus generated non-repetitive pseudo-random numbers!!
Now my code is working fine
Once again I thank you all especially OrangeDog!! :) :) :) :)with warm regards,
Sruthi :)
Similar Threads
-
Urgent Help needed!
By mlwong in forum New To JavaReplies: 0Last Post: 03-19-2009, 08:51 AM -
Help needed for strings....urgent
By pankbiet in forum New To JavaReplies: 6Last Post: 02-17-2009, 09:24 AM -
hi help needed, this is urgent
By msciriha in forum NetBeansReplies: 1Last Post: 02-07-2009, 06:16 PM -
Urgent help needed here pls!!
By Manfizy in forum NetBeansReplies: 5Last Post: 01-28-2009, 07:38 AM -
urgent help needed - paper submission.
By dirtycash in forum New To JavaReplies: 2Last Post: 11-23-2007, 11:24 AM


LinkBack URL
About LinkBacks

Bookmarks