Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Photo Encryption Problem--can't find bug!

 
Karyn Mizerski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you verified that lines 39 to 49 do what you expect them to do?
 
Karyn Mizerski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1253
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is sbyte used for?
 
Stevens Miller
Bartender
Posts: 1253
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1253
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1253
24
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic