writing a cryptoquip in java

Discussion in 'OT Technology' started by funkyted, Mar 1, 2007.

  1. funkyted

    funkyted Wooo College! No Parents!

    Joined:
    Jul 13, 2006
    Messages:
    2,392
    Likes Received:
    0
    Location:
    Baltimore and Philadelphia
    yea this is for an intro java class so no i'm not expecting the answer already typed out for me, but i was wondering if i could get any tips on how to make a method that would generate a cryptoquip

    for those who don't know a cryptoquip assigns a new letter to every letter of a line. it basically changes the line into a coded language.
    how can i make every letter get changed to a different letter, while making sure no letter gets repeated and no letter gets substituted with its original letter.

    any help would be appreciated.
     
  2. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
  3. funkyted

    funkyted Wooo College! No Parents!

    Joined:
    Jul 13, 2006
    Messages:
    2,392
    Likes Received:
    0
    Location:
    Baltimore and Philadelphia
    well i could do that with every letter assigning it another random letter.
    but how could i make sure that no two letters got the same new letter because i'm supposed to do it with the random function.
     
  4. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    One method you could use to generate your substitution is to create an ArrayList containing all 26 characters in the alphabet. Then use the random number generator to pick one of the remaining letters and remove in from the ArrayList. If the letter you randomly chose is the same as the one your are picking for, skip the result and try again. Keep going until all of the letters are chosen. If you end up with the case where the last letter is the same as what it will be substituting for, throw away the results and try again.
     
  5. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    Just add 1 to the ascii code for that letter. Then just do a simple check for z and/or Z and wrap those back around to the a or A, respectively.

    Since you are in an intro java class, your code doesn't have to be secure so this simple idea should work. Unless I'm missing something.
     

Share This Page