Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help understanding steganography code

  1. #1
    nrott is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Need help understanding steganography code

    Hi all, I need help understanding what this code i got online means, like what is the steganography algorithm used and how does it actually stores the message within the image. I really appreciate it, Thanks.

    Here is the encryption part

    Java Code:
    public void Imageencrypt(String message,File file,int key) throws java.io.IOException 
        {
        byte b[]=new byte[2];
        
        BigInteger Abi,Mbi;
        int k,k1;
        DataInputStream ins=new DataInputStream(new FileInputStream(file));
        DataOutputStream outs=new DataOutputStream(new FileOutputStream(new File("1.jpg")));
        for(int c=0;c<key;c++)
         {
          int ch=ins.read();
          outs.write(ch);
         }
        int len=message.length();
        byte mess[]=new byte[2];
        char chmess[]=new char[len+1];
        k=k1=0;
        for(int i=0;i<=len;i++)
         {
          message.getChars(0,len,chmess,0);
          if(i==0)
           {
            BigDecimal bd=new BigDecimal(len);
            BigInteger Blen=bd.toBigInteger();
            String Slen=Blen.toString(2);
            char Clen[]=new char[Blen.bitLength()];
            Slen.getChars(0,Blen.bitLength(),Clen,0);
            for(int j=0;j<=7;j++)
             {
              if(j==0)
               {
                for(k=0;k<8-Blen.bitLength();k++)
                 {
                  int n=ins.read(b);
                  Abi=new BigInteger(b);
                  String Aby=Abi.toString(2);
                  int Alen=Abi.bitLength();
                  if(b[0]<0)
                    Alen++;
                  char Ach[]=new char[Alen+1];
                  Aby.getChars(0,Alen,Ach,0);
    
    	      if(b[0]==0)
    	       {
    	       }
    	      else
    	       {
                  if(Ach[Alen-1]=='1')
                   {
                    if(Alen==Abi.bitLength())
    		 {
                      BigInteger bi=new BigInteger("1111111111111110",2);
                      BigInteger big=Abi.and(bi);
    		  b=big.toByteArray();
    		 }
     		else
    		 {
      	                  BigInteger bi=new BigInteger("-1",2);
            	          BigInteger big=Abi.subtract(bi);
    		  b=big.toByteArray();
    		 }
                   }
    		outs.write(b);
      	       }
               }  
             j=j+k-1;
             } 
        		else
    	         {
            	  int n=ins.read(b);
    	          Abi=new BigInteger(b);
            	  String Aby=Abi.toString(2);
    	          int Alen=Abi.bitLength();
                      if(b[0]<0)
                      Alen++;
    	          char Ach[]=new char[Alen+1];
    	          Aby.getChars(0,Alen,Ach,0);
    	         if(b[0]==0)
            	  {
                       Alen=1;
    	          }
    	            if(Clen[j-k]=='0' && Ach[Alen-1]=='1')
            	     {
                           if(Alen==Abi.bitLength())
                            {
                     	 BigInteger bi=new BigInteger("1111111111111110",2);
    	                 BigInteger big=Abi.and(bi);
    			 b=big.toByteArray();
                            }
                           else
                            {
      	                  BigInteger bi=new BigInteger("-1",2);
            	          BigInteger big=Abi.subtract(bi);
    			 b=big.toByteArray();
                            }
                 	     }
    	            else if(Clen[j-k]=='1' && Ach[Alen-1]=='0')
            	     {
                          if(Alen==Abi.bitLength())
    			 {
                    	BigInteger bi=new BigInteger("1",2);
    			BigInteger big=Abi.add(bi);
    			b=big.toByteArray();
    			 }
                          else
    			 {
                    	BigInteger bi=new BigInteger("-1",2);
    			BigInteger big=Abi.add(bi);
    			b=big.toByteArray();
    			 }
    
            	     }
           		   outs.write(b);
                     } 
    
        	    } 
    
            } 
    
          else
           {
            String slen=String.valueOf(chmess[i-1]);
            byte blen[]=slen.getBytes();
            BigInteger Blen=new BigInteger(blen);
            String Slen=Blen.toString(2);
            char Clen[]=new char[Blen.bitLength()];
            Slen.getChars(0,Blen.bitLength(),Clen,0);
            for(int j=0;j<=7;j++)
             {
              if(j==0)
               {
                for(k1=0;k1<8-Blen.bitLength();k1++)
                 {
                  int n=ins.read(b);
                  Abi=new BigInteger(b);
    	      String Aby=Abi.toString(2);
                  int Alen=Abi.bitLength();
                      if(b[0]<0)
                      Alen++;
                  char Ach[]=new char[Alen+1];
                  Aby.getChars(0,Alen,Ach,0);
     		if(b[0]==0)
    		       {
    
    		       }
    	      else
    	       {
    	              if(Ach[Alen-1]=='1')
            	       {
                            if(Alen==Abi.bitLength())
                             {
                    	  BigInteger bi=new BigInteger("1111111111111110",2);
    	                  BigInteger big=Abi.and(bi);
    			  b=big.toByteArray();
                             }
                            else
                             {
      	                  BigInteger bi=new BigInteger("-1",2);
            	          BigInteger big=Abi.subtract(bi);
    			  b=big.toByteArray();
                             }
            	       }
    	       }
    		outs.write(b);
    
                  }  
    
    		j=j+k1-1;
    
                 } 
    
            else
             {
              int n=ins.read(b);
               Abi=new BigInteger(b);
                  String Aby=Abi.toString(2);
                  int Alen=Abi.bitLength();
                      if(b[0]<0)
                      Alen++;
                  char Ach[]=new char[Alen+1];
                  Aby.getChars(0,Alen,Ach,0);
          		if(b[0]==0)
    		       {
    			Alen=1;
    		       }
    
    	            if(Clen[j-k1]=='0' && Ach[Alen-1]=='1')
    	             {
    			if(Alen==Abi.bitLength())
     			 {
      	                  BigInteger bi=new BigInteger("1111111111111110",2);
            	          BigInteger big=Abi.and(bi);
    			  b=big.toByteArray();
                             }
                            else
     			 {
      	                  BigInteger bi=new BigInteger("-1",2);
            	          BigInteger big=Abi.subtract(bi);
    			  b=big.toByteArray();
                             }
    	             }
            	    else if(Clen[j-k1]=='1' && Ach[Alen-1]=='0')
    	             {
    			if(Alen==Abi.bitLength())
    			 {
      		     	  BigInteger bi=new BigInteger("1",2);
                    	  BigInteger big=Abi.add(bi);
    			  b=big.toByteArray();
     			 }
    			else
    			 {
      		     	  BigInteger bi=new BigInteger("-1",2);
                    	  BigInteger big=Abi.add(bi);
    			  b=big.toByteArray();
     			 }
            	     }
    		outs.write(b);
             } 
    
           } 
         } 
    
       } 
    
      while(true)
       {
        int i=ins.read();
        if(i==-1) break;
        outs.write(i);
       }
        ins.close();
        outs.close();
       }

    Decryption Part
    Java Code:
       public void Imagedecrypt(File filename,int key)throws java.io.IOException
     {
     FileInputStream ins=new FileInputStream(filename);
      byte b[]=new byte[2];
      BigInteger bb1;
      char mess[]=new char[8];
      int c=0;
      for(int i=0;i<key;i++)
      {
       int n=ins.read();
      }
      for(int i=0;i<8;i++)
       {
        ins.read(b);
        bb1=new BigInteger(b);
        String str=bb1.toString(2);
        int len=bb1.bitLength();
        if(b[0]<0)
         len++;
        char ch[]=new char[len+1];
        str.getChars(0,len,ch,0);
        if(b[0]==0)
         mess[i]='0';
        else
         mess[i]=ch[len-1];
       }
      String dd=new String(mess);
      BigInteger bb=new BigInteger(dd,2);
      String s=bb.toString(2);
     int l=bb.intValue();
    
    char me[]=new char[l];
    int count=0;
    
    for(int m=0;m<l;m++)
     {
    for(int i=0;i<8;i++)
       {
        ins.read(b);
        bb1=new BigInteger(b);
        String str=bb1.toString(2);
        int len=bb1.bitLength();
        if(b[0]<0)
         len++;
        char ch[]=new char[len+1];
        str.getChars(0,len,ch,0);
        if(b[0]==0)
         mess[i]='0';
        else
         mess[i]=ch[len-1];
       }
      String dd1=new String(mess);
      BigInteger bb2=new BigInteger(dd1,2);
      String s1=bb2.toString(2);
     int l1=bb2.intValue();
     me[count]=(char)l1;
     count++;
     }
    String message=new String(me);
    textarea3.setText(message);
    ins.close();
    
     }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help understanding steganography code

    You might want to mention what parts of the code above you specifically you don't understand. If it's "everything" then perhaps you need to do some background work first to learn what algorithms are possible here.
    DarrylBurke likes this.

  3. #3
    nrott is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Need help understanding steganography code

    Quote Originally Posted by Fubarable View Post
    You might want to mention what parts of the code above you specifically you don't understand. If it's "everything" then perhaps you need to do some background work first to learn what algorithms are possible here.
    Hi, sorry about that. I was wondering what this part means:

    Java Code:
    BigInteger bi=new BigInteger("1111111111111110",2);
                          BigInteger big=Abi.and(bi);
    another question, the app had a function which protects the image with a key where the correct key has to be entered before the image can be decrypted. Below is the code for it, does it converts the key to binary and store it in the image?

    Java Code:
             else
             {
         
              int key=Integer.parseInt(Ekey);
             Imageencrypt(textarea2.getText(),Ofilename,key);
              Cencrypt=1;
    Thanks for your help!

  4. #4
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: Need help understanding steganography code

    Java Code:
    else
    {
     
     int key=Integer.parseInt(Ekey);
    Imageencrypt(textarea2.getText(),Ofilename,key);
     Cencrypt=1;
    The above code does not convert something to Binary, as far as it looks on here. Integer.parseInt(String) only correctly parses denary numbers. The code you've posted is a little bit wierd and tricky too follow, but if you point blank don't understand any of it, why oh why did you download the source code in the first place? I strongly recommend you go and educate yourself about this topic and the various algorithms and designs involved before you just try and read a wall of code like this.

Similar Threads

  1. Urgent help understanding code
    By varons666 in forum New To Java
    Replies: 3
    Last Post: 06-03-2011, 07:51 PM
  2. need help understanding part of code
    By mustachMan in forum New To Java
    Replies: 7
    Last Post: 02-09-2011, 07:11 PM
  3. Steganography
    By AedonetLIRA in forum New To Java
    Replies: 5
    Last Post: 01-11-2011, 04:25 PM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. trouble understanding code help
    By yasmin k in forum New To Java
    Replies: 4
    Last Post: 11-16-2009, 09:46 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
  •