Results 1 to 6 of 6

Thread: Rot-13

  1. #1
    wiggitywam23 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default 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 06:35 PM. Reason: forgot my code.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agree. As written your question is nothing but a classic "homework dump". Let's see some evidence of some effort on your part.

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    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.

  5. #5
    wiggitywam23 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    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.

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    if it's working then sure why not lol
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •