I've been working on a java program that decrypts and encrypts Rot-13 messages. The additional requirements for this program are that the program must only encrypt alphabetical letters (leave any other symbols, numbers, characters unchanged) and the methods within this program must be the ones I've used in the following code (along with the same parameters and signatures).
The problem i keep having is that when i run the program, the output is numerical for any character instead of producing the desired Rot-13 decryption. For example: when i input "zzz", the program outputs "109109109". I understand that its some how giving me the decimal number of its character but i don't know how i can fix (this is after 2 days of messing around with the code). I have a feeling the solution is something extremely simple (hopefully). However i'm unable to figure this out on my own at this point. If someone could read over this code and provide me with some kind of help, i would be really grateful :) .
Greg Charles wrote:rotateCharacter() returns an int, so you are concatenating a series of ints to the "complete" String.
If that's the problem, how would I translate the integers returned by the rotateCharacter() method in decrypt(), so its concatenating the encrypted/decrypted letters along with any unchanged numbers/symbols?
Jeff Verdegan wrote:The method should return a char, not an int. And it should take a char as its parameter too. After all, its job is to turn on char into another char.
What would I specifically change in the code. When I change the int parameter to a char the program's output still doesn't work and now I'm noticing that the output is encrypting every character as "109" and adding them to one string. Example: "zz,," = "109109109109"
Nevermind with the problem of repeating the first index position (i fixed that). Just still having trouble in figuring out what I specifically should change in the code (in changing the methods parameter from int to char)
Thomas Crew wrote:Nevermind with the problem of repeating the first index position (i fixed that). Just still having trouble in figuring out what I specifically should change in the code (in changing the methods parameter from int to char)
You deleted your code, so I don't know what to tell you other than have the method accept and return a char. You can do math on a char just like on an int. For instance 'D' - 2 gives 'B' (although you'll probably have to cast the result to char).
Take your best shot, and if you get stuck, post your code and ask a specific question about what you're having trouble with.
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad: