Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default [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 :)

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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.

  3. #3
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    @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
    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);
    Why is this happening???
    Any help is appreciated.
    Thank you
    with warm regards,
    Sruthi :)

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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 :(

  5. #5
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 class
    with warm regards,
    Sruthi :)

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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.

  7. #7
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 you
    with warm regards,
    Sruthi :)

  8. #8
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    @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 :)

  9. #9
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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)

  10. #10
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 :)

  11. #11
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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.

  12. #12
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    Are you sure you're not saving the image in a lossy format?

  13. #13
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 properly
    with warm regards,
    Sruthi :)

  14. #14
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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:
    Java Code:
    try{
    	PixelGrabber grabber = new PixelGrabber(org, 0, 0, org_width, org_height, org_pixelarr,0,org_width); 
    	grabber.grabPixels();
             } catch (InterruptedException ie) { }
    Here is the code that is used to store the image
    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 :)

  15. #15
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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?

  16. #16
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 appreciated
    with warm regards,
    Sruthi :)

  17. #17
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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 10:56 PM.

  18. #18
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    hmmm
    Thanks for the reply!!
    I will check it out surely!!
    with warm regards,
    Sruthi :)

  19. #19
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    @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 :)

  20. #20
    sruthi_2009 is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    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 :)

Page 1 of 2 12 LastLast

Similar Threads

  1. Urgent Help needed!
    By mlwong in forum New To Java
    Replies: 0
    Last Post: 03-19-2009, 09:51 AM
  2. Help needed for strings....urgent
    By pankbiet in forum New To Java
    Replies: 6
    Last Post: 02-17-2009, 10:24 AM
  3. hi help needed, this is urgent
    By msciriha in forum NetBeans
    Replies: 1
    Last Post: 02-07-2009, 07:16 PM
  4. Urgent help needed here pls!!
    By Manfizy in forum NetBeans
    Replies: 5
    Last Post: 01-28-2009, 08:38 AM
  5. urgent help needed - paper submission.
    By dirtycash in forum New To Java
    Replies: 2
    Last Post: 11-23-2007, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •