Results 1 to 6 of 6
Thread: Rot-13
- 10-28-2009, 05:08 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
Rot-13
Start by writing a class to encode text using Rot-13. The class you write must be named RotDecryptor.
Decompose the problem by first writing and testing a method to encode a single character. This method must named rotateCharacter and have the following signature:
public int rotateCharacter( int aCharacter )
This method will take a single parameter that is the integer code for one character (which may or may not be a letter). It then returns the integer code for the "encrypted Rot-13 version" of that character.
So far I've done this, which successfully rotates is, however, I was wondering if there was an easier way to write it, maybe using a for loop.
public int rotateCharacter( int aCharacter )
{
if((aCharacter >= 65) && (aCharacter <= 78))
{
aCharacter += 13;
}
else if((aCharacter >= 79) && (aCharacter <=90))
{
aCharacter -= 13;
}
if((aCharacter >= 97) && (aCharacter <= 110))
{
aCharacter += 13;
}
else if((aCharacter >= 111) && (aCharacter <=122))
{
aCharacter -= 13;
}
System.out.println((char)aCharacter);
return aCharacter;
}Last edited by wiggitywam23; 10-28-2009 at 05:35 PM. Reason: forgot my code.
- 10-28-2009, 05:10 PM #2
What's your question? Nobody here will write your homework for you. Start by posting some work you've done and any errors you're receiving and we can give advice and show you how to fix said errors.
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
-
Agree. As written your question is nothing but a classic "homework dump". Let's see some evidence of some effort on your part.
- 10-28-2009, 05:36 PM #4
You could use an array that stores a-z, or you can pretty much just do what you're doing now. Both ways though require that you return to the starting position is the character is within 13 spots from the end.
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
- 10-28-2009, 05:48 PM #5
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
cant I just change the if statements, to ...
if((aCharacter >= 65) && (aCharacter < 78))
else if((aCharacter >= 78) && (aCharacter <91))
if((aCharacter >= 97) && (aCharacter < 110))
else if((aCharacter >= 110) && (aCharacter < 123))
it seems to be working.
- 10-28-2009, 08:04 PM #6


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks