Problems with regenerating a steganography-file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with regenerating a steganography-file

Fabian Pursche
Hello,

I'm trying to write two Plugins for ImageJ to hide a file in picture (8-bit
greyshade) and two read it out again. It works quite well, but I don't know
how to fit the new file right. I've implemented a header of two bytes in
front of my fileInputStream, but after regaining the header, the filesize
doesn't match.

Here are both codes:

//written by F.Pursche 2008

import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;
import java.io.*;

public class Steganography_ implements PlugInFilter{

        public int setup (String arg, ImagePlus imp) {
        return DOES_8G;
    }

        public void run (ImageProcessor ip) {

                int w = ip.getWidth();
        int h = ip.getHeight();
        int maxsize = w*h;
        int counter;
        long header;
        counter = 0;
        header = 0;
        Exception E = null;

        File file = new File("C:\\source.txt");
        try{
        if(file.exists()){
        FileInputStream stream = new FileInputStream(file);
        if (((stream.available()*8)-16) > maxsize){throw E;}
        else{
        int buffer;
        int fileSize = stream.available();
        int fileSizeH = ((fileSize & 65280)/ 256);
        int fileSizeL = fileSize & 255;
        int firstByte = 0;

        for (int x=0; x<w; x++) {
        for (int y=0; y<h; y++) {

        if(header == 0){
                buffer = fileSizeH;
                }
                if(header == 1){
                buffer = fileSizeL;
                }
                else{
                buffer = firstByte;
                }
        int bit = 0;
        int lsb = 0;
        int p = 0;
        int pixel = ip.getPixel(x, y);

        if(counter == 0){
        lsb = buffer & 1;
        if(lsb == 1){
        bit = 1;
        }
        }
        if(counter == 1){
        lsb = buffer & 2;
        if(lsb == 2){
        bit = 1;
        }
        }
        if(counter == 2){
        lsb = buffer & 4;
        if(lsb == 4){
        bit = 1;
        }
        }
        if(counter == 3){
                        lsb = buffer & 8;
                        if(lsb == 8){
        bit = 1;
        }
                        }
        if(counter == 4){
                        lsb = buffer & 16;
                        if(lsb == 16){
        bit = 1;
        }
                        }
        if(counter == 5){
                        lsb = buffer & 32;
                        if(lsb == 32){
        bit = 1;
        }
                        }
        if(counter == 6){
                        lsb = buffer & 64;
                        if(lsb == 64){
        bit = 1;
        }
                        }
        if(counter == 7){
                        lsb = buffer & 128;
                        if(lsb == 128){
        bit = 1;
        }
                        counter = -1;
                        header++;
                        if(header > 1){
                        buffer=stream.read();
                        }

                        }

        p = (pixel & 254) + bit;

        ip.putPixel(x,y,p);
        counter++;

        }
        }
        }

        }
        }
        catch (Exception e) {
        System.out.println(e.toString());
        }


        }
}



2nd code:

//written by F.Pursche 2008

import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;
import java.io.*;

public class ReSteganography_ implements PlugInFilter{

        public int setup (String arg, ImagePlus imp) {
        return DOES_8G;
    }

        public void run (ImageProcessor ip) {

                int w = ip.getWidth();
        int h = ip.getHeight();

        int counter, sizeCounter;
        counter = 0;
        sizeCounter = 0;
        long header = 0;
        int buffer=0;
        int fileSize, fileSizeH, fileSizeL;
                fileSizeH = 0;
                fileSizeL = 0;
                fileSize = -1;

        File file = new File("C:\\newfile.txt");
        try{

        FileOutputStream stream = new FileOutputStream(file);

        for (int x=0; x<w; x++) {
        for (int y=0; y<h; y++) {
        int bit = 0;
        int lsb;

        int pixel = ip.getPixel(x, y);

        lsb = pixel & 1;

        if(counter == 0){
        if(lsb == 1){
        bit = 1;
        buffer = buffer | bit;
        }
        }
        if(counter == 1){
        if(lsb == 1){
        bit = 2;
        buffer = buffer | bit;
        }
        }
        if(counter == 2){
        if(lsb == 1){
        bit = 4;
        buffer = buffer | bit;
        }
        }
        if(counter == 3){
                        if(lsb == 1){
        bit = 8;
        buffer = buffer | bit;
        }
                        }
        if(counter == 4){
                        if(lsb == 1){
        bit = 16;
        buffer = buffer | bit;
        }
                        }
        if(counter == 5){
                        if(lsb == 1){
        bit = 32;
        buffer = buffer | bit;
        }
                        }
        if(counter == 6){
                        if(lsb == 1){
        bit = 64;
        buffer = buffer | bit;
        }
                        }
        if(counter == 7){
                        if(lsb == 1){
        bit = 128;
        buffer = buffer | bit;
        }

                        if(header == 0){
                        fileSizeH = buffer;
                        }
                        if(header == 1){
                        fileSizeL = buffer;
                        fileSize = (fileSizeH * 256) | fileSizeL;

                        }
                        if(header > 1){
                        if(sizeCounter <= fileSize){
                        stream.write(buffer);
                        sizeCounter++;

                        }

                        }
                        header++;
                        buffer = 0;
                        counter = -1;
                        }
        counter++;
        }
        }
        stream.close();
        }

        catch (Exception e) {
        System.out.println(e.toString());
        }
        }
}


Just change the file in the first filter, maybe a txt-file.


Thanks
Fabian
Reply | Threaded
Open this post in threaded view
|

Problem with Version 1.40b!!

Joachim Wesner
Hi list,

I just noted that upgrading to ImageJ 1.40b messes with my "locale",
suddenly the decimal "point" becomes a comma in input boxes etc. (German
setup), breaking a lot of my Plugins!
After downgrading to 1.39x everything is OK again! I´m not sure  if this
already existed with 1.40a, due to the new nice updater mechanism I dont
have a copy anymore.

Any ideas?

(Windows 2000, Imagej bundled Java 1.6.0_02)


Joachim








______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Version 1.40b!!

dscho
Hi Joachim,

On Wed, 2 Apr 2008, Joachim Wesner wrote:

> I just noted that upgrading to ImageJ 1.40b messes with my "locale",
> suddenly the decimal "point" becomes a comma in input boxes etc. (German
> setup), breaking a lot of my Plugins!
>
> After downgrading to 1.39x everything is OK again! I´m not sure if this
> already existed with 1.40a, due to the new nice updater mechanism I dont
> have a copy anymore.

Do you mean 1.38x, or 1.39u?  I never had 1.39x.

In case you meant 1.39u, I cannot find anything in the changes that
relates to the locale, except the use of toLowerCase(Locale.US), which is
used throughout the code, though.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: Problem with Version 1.40b!!

Joachim Wesner
Sorry, typo, I meant 1.39u

Yep, strange, I will need to check this with my other system at home.

I´m not totally sure if I did something strange recently that caused this,
nevertheless I can now switch on and off this effect by simply changing
versions
via the Updater (still the extra plugin)

Is there anything in IJ_prefs.txt handling that might be related to version
numbering?
So that 1.40 reads IJ_prefs differntly from 1.39u?

Joachim



                                                                           
             Johannes                                                      
             Schindelin                                                    
             <Johannes.Schinde                                          An
             [hidden email]>                Joachim Wesner                    
                                        <joachim.wesner@LEICA-MICROSYSTEMS
             02.04.2008 18:10           .COM>                              
                                                                     Kopie
                                        [hidden email]                
                                                                     Thema
                                        Re: Problem with Version 1.40b!!  
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi Joachim,

On Wed, 2 Apr 2008, Joachim Wesner wrote:

> I just noted that upgrading to ImageJ 1.40b messes with my "locale",
> suddenly the decimal "point" becomes a comma in input boxes etc. (German
> setup), breaking a lot of my Plugins!
>
> After downgrading to 1.39x everything is OK again! I´m not sure if this
> already existed with 1.40a, due to the new nice updater mechanism I dont
> have a copy anymore.

Do you mean 1.38x, or 1.39u?  I never had 1.39x.

In case you meant 1.39u, I cannot find anything in the changes that
relates to the locale, except the use of toLowerCase(Locale.US), which is
used throughout the code, though.

Ciao,
Dscho


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Version 1.40b!!

Wayne Rasband
In reply to this post by Joachim Wesner
> I just noted that upgrading to ImageJ 1.40b messes with my "locale",
> suddenly the decimal "point" becomes a comma in input boxes etc.
> (German setup), breaking a lot of my Plugins!
> After downgrading to 1.39x everything is OK again! I´m not sure  if
> this already existed with 1.40a, due to the new nice updater
> mechanism I don't have a copy anymore.

This bug is fixed in v1.40c, now available via the
Plugins>Utilities>Update ImageJ command.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Version 1.40b!!

Richard Cole
Dear Group,

OK, maybe I am a little slow on the uptake here, but I do not see the
Plugins>Utilities>Update ImageJ command.  I use to download the jar from the
ImageJ website and drop it in the correct folder.

Cheers

RWC




 
Richard Cole
Research Scientist IV
Director: Advanced Light Microscopy Core Unit
Wadsworth Center
P.O. Box 509 Albany N.Y. 12201-0509
518-474-7048 Phone
518-474-4430 Fax
 
Email [hidden email]
Website www.wadsworth.org/cores/alm/index.htm
 
 
-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Wayne
Rasband
Sent: Wednesday, April 02, 2008 1:58 PM
To: [hidden email]
Subject: Re: Problem with Version 1.40b!!

> I just noted that upgrading to ImageJ 1.40b messes with my "locale",
> suddenly the decimal "point" becomes a comma in input boxes etc.
> (German setup), breaking a lot of my Plugins!
> After downgrading to 1.39x everything is OK again! I´m not sure  if
> this already existed with 1.40a, due to the new nice updater
> mechanism I don't have a copy anymore.

This bug is fixed in v1.40c, now available via the
Plugins>Utilities>Update ImageJ command.

-wayne



IMPORTANT NOTICE: This e-mail and any attachments may contain
confidential or sensitive information which is, or may be, legally
privileged or otherwise protected by law from further disclosure.  It
is intended only for the addressee.  If you received this in error or
from someone who was not authorized to send it to you, please do not
distribute, copy or use it or any attachments.  Please notify the
sender immediately by reply e-mail and delete this from your
system. Thank you for your cooperation.
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: Problem with Version 1.40b!!

Joachim Wesner
Hi RWC.

Haha, you are a victim of a "Catch22" situation, if your version is too
old, you also do not yet have the Updater to upgrade! ;-((

Sincerely, at best you get the external updater plugin  from

http://rsb.info.nih.gov/ij/plugins/imagej-updater.html

first, only the newest versions have this updater built in as indicated!

Sincerely

Joachim


ImageJ Interest Group <[hidden email]> schrieb am 02.04.2008 22:11:41:

> Dear Group,
>
> OK, maybe I am a little slow on the uptake here, but I do not see the
> Plugins>Utilities>Update ImageJ command.  I use to download the jar from
the

> ImageJ website and drop it in the correct folder.
>
> Cheers
>
> RWC
>
>
>
>
>


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________