Java Encryptor - strange output


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Java Encryptor - strange output

  1. #1
    Join Date
    Nov 2002
    Location
    ftcky
    Posts
    6

    Java Encryptor - strange output

    Hey all,

    I hope someone can shed some light on this small problem I have. Ok, here goes. I love to do cryptoquotes (or celebrity cyphers, whatever your newspaper calls them) and so does my fiance. I like to send her emails with small cyphers in them but hate having to change all the letters manually.

    I thought it would be fun to make a real quick program in java to do this for me, automate the whole process of encrypting and decyphering. I stopped after i made the encryption part because it wasnt outputting what it should have been.

    I have attached a zipped folder of the three files i have and at the bottom of cryptoquote.java i have what it does output and what it should output. I also placed some code in the method that encrypts the input string to output each step since i lack a compiler that lets you stop and walk through each line of code.

    Please any help on this problem would be greatly appreciated. I know the code is pretty rough but I have yet to refine it all...took me 15 minutes to write it all so I am open to any critiquing.
    Attached Files Attached Files
    TIA,
    Matt

  2. #2
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Hi there, I browsed you code but stopped to find the error. Since you're still in the beginning of your project I think it would be wise to do it a bit different. It's better to work wth char's instead of String's when you're doing this kind of thing.
    I attached an example I coded for you. Please bare in mind that there are a lot of flaws in the performance of the encryption, but it's very simple and I think you'll only be using it to encrypt small messages, so you'll be ok. And you can, of course, modify it to your wishes!
    It reads and writes the messages and your encryption key from file instead of a console (more conveniet I think).

    Do post again if you're having trouble with decrypting messages from your fiance (wish my girlfriend found this interesting...). That's where the real fun begins!

    Good luck.
    Attached Files Attached Files

  3. #3
    Join Date
    May 2005
    Posts
    25
    It dosnt work because of this

    if(checker.compareToIgnoreCase("a")==1)

    the above code is saying, IF ( checker IS 1 letter above A )

    what you need to have is this

    if(checker.compareToIgnoreCase("a")==0)

    this says , IF ( checker IS equal to a )


    the way the compareToIgnoreCase method works is weird, it returns a negative if the letter is lower, a zero if its the same, or a positive if its higher.

    http://java.sun.com/j2se/1.5.0/docs/...ng/String.html
    scroll down to the compareToIgnoreCase method and read its description.


    so change all the ones to zeros, and it will work. this had me confused at first too, but after i looked at the API i noticed this method dosnt go by 0 or 1.

  4. #4
    Join Date
    Nov 2002
    Location
    ftcky
    Posts
    6

    Makes sense now...

    Hey thanks, now that you say that it does ring a bell. I have taken quite some time off from coding and I totally forgot about that. Thanks for your help in solving this little problem, from now on I will be sure to check the API just to make sure its not a simple fix like that...haha, i feel silly after reading the solution.

    Thanks again,
    Matt
    TIA,
    Matt

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 04:16 PM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  3. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 06:32 PM
  4. Replies: 0
    Last Post: 02-01-2002, 12:08 AM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 05:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center