wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Photo Encryption Problem--can't find bug! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Photo Encryption Problem--can Watch "Photo Encryption Problem--can New topic
Author

Photo Encryption Problem--can't find bug!

Karyn Mizerski
Greenhorn

Joined: Feb 03, 2013
Posts: 4
Hi everyone! I am working on a variation to the princeton.edu PhotoMagic LFSR problem found here: http://www.cs.princeton.edu/courses/archive/fall09/cos126/assignments/lfsr.html. Here is my issue. I know that my Random Bit Generator is working correctly as I have extensively tested it with the provided data. Somewhere in my PhotoMagic code, I am messing something up. The encrypted image should look like this:

but instead I am getting this:

What am I doing wrong? Here is my code:




Any help would be greatly appreciated!

Thanks!
Karyn
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41806
    
  62
How have you verified that lines 39 to 49 do what you expect them to do?


Ping & DNS - my free Android networking tools app
Karyn Mizerski
Greenhorn

Joined: Feb 03, 2013
Posts: 4
Probably not since you've pointed it out . But I I just tested those steps and they didn't seem to work any differently than I expected them too. Producing the String representation of the color with

String BinaryRed = String.format("%8s", Integer.toBinaryString(red)).replace(' ', '0');

gave me an 8 digit binary string, which I them used the xor class to xor it with the 8 randomly generated bits and I got 8 new bits.
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

What is sbyte used for?
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Also, are you expecting RandomBitGenerator.generate(8, GenP, tap) to produce a different number for each pixel? Without its code, I can't tell if it will, but if it doesn't, it seems you are XORing your original image with a solid gray image.
Karyn Mizerski
Greenhorn

Joined: Feb 03, 2013
Posts: 4
Bug fixed!! Stevens Miller- you pointing out that I hadn't used sbyte showed me my error. I decided to eliminate my xor method and instead convert the ints red, green, and blue to bytes. Then I used the ^ operator to get a new byte. That did the trick.

You guys are awesome! Woo Photo Magic!

Thanks everyone
-Karyn
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Karyn Mizerski wrote:Bug fixed!! Stevens Miller- you pointing out that I hadn't used sbyte showed me my error. I decided to eliminate my xor method and instead convert the ints red, green, and blue to bytes. Then I used the ^ operator to get a new byte. That did the trick.

You guys are awesome! Woo Photo Magic!

Thanks everyone
-Karyn

Glad to help. Do you use an IDE? NetBeans puts a little wavy grey line underneath any variable that isn't used, which is often a flag that should get your attention. Here, sbyte is "used" to hold a value, but NetBeans is smart enough to realize that can't make any difference to the execution of your program, and marks it as "unused" anyway. (NetBeans also correctly points out that the value used to initialize useMe is never used; at lines 30 and 35, you are assigning String references which overwrite the reference assigned in line 23, which you can just leave out.)
Karyn Mizerski
Greenhorn

Joined: Feb 03, 2013
Posts: 4
I did use NetBeans, but in my frustration, I was ignoring the gray wavy lines. It helps a lot to have another set of eyes look at it to point out what you're looking over.
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Karyn Mizerski wrote:I did use NetBeans, but in my frustration, I was ignoring the gray wavy lines. It helps a lot to have another set of eyes look at it to point out what you're looking over.

Sister, I feel your pain (or your relief, I guess). Before the internet, another set of eyes tended to come along only every few days. Now, you can get them on-demand (and without feeling sheepish later at work).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Photo Encryption Problem--can't find bug!