Cipher ALphabet Arranging help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 2
Reputation: Merumi is an unknown quantity at this point 
Solved Threads: 0
Merumi Merumi is offline Offline
Newbie Poster

Cipher ALphabet Arranging help

 
0
  #1
Apr 16th, 2008
Hey guys I hope you can help me with this problem, its like a minor problem.

----PROBLEM-----
I don't know how to generate the secret code... meaning if the input was:
{
c.println (generateCipherAlphabet ("COMPUTER SCIENCE));
}

Above only outputs "COMPUTERSINQVWXYZABDFGHJKL" which is the cipher alphabet only

I want it to output "CQHOVJMWKPXLUYTZEARBSDIFNG" which is the secret code.. how do I do that? I was thinking of some for loops if it is can ya help me construct one?


  1. public class GenerateCipher
  2. {
  3.  
  4. /** To generate keyPhrase into cipher alphabet and secret code
  5.   * @param keyPhrase keyPhrase to be changed
  6.   * @return changed keyPhrase
  7.   */
  8. public static String generateCipherAlphabet (String keyPhrase)
  9. {
  10. //defines the variables and creates alphabet string
  11. String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  12. String realStr = "";
  13. String newStr = "";
  14. //for loop combined to delete the punctuations and spaces
  15. for (int index = 0 ; index < keyPhrase.length () ; index++)
  16. {
  17. char character = keyPhrase.charAt (index);
  18. if (Character.isLetter (character))
  19. {
  20. newStr += character;
  21. }
  22. }
  23. //for loop to remove the duplicated letters from the keyPhrase
  24. for (int position = 0 ; position < newStr.length () ; position++)
  25. {
  26. char removeLetter = newStr.charAt (position);
  27. //detects for the duplicated letters remaining in keyPhrase
  28. if (realStr.lastIndexOf (removeLetter, position - 1) == -1)
  29. {
  30. realStr += removeLetter;
  31. }
  32. }
  33. //starts at the end of the keyPhrase to add the alphabets
  34. char searchLetter = realStr.charAt (realStr.length () - 1);
  35. //for loop to add the alphabet starting from the searchLetter to the end
  36. for (int position = (alphabet.indexOf (searchLetter)) ; position < alphabet.length () ; position++)
  37. {
  38. char letterAdded = alphabet.charAt (position);
  39. //if statement when there is a duplicated letter from the cipher
  40. if (realStr.lastIndexOf (letterAdded, position - 1) == -1)
  41. {
  42. realStr += letterAdded;
  43. }
  44. }
  45. //for loop that adds the alphabet from the beginning of keyPhrase
  46. for (int position = 0 ; position < alphabet.indexOf (searchLetter) ; position++)
  47. {
  48. char letterAdded2 = alphabet.charAt (position);
  49. //if statement when there is a duplicated letter from the beginning of the cipher
  50. if (realStr.lastIndexOf (letterAdded2) == -1)
  51. {
  52. realStr += letterAdded2;
  53. }
  54. }
  55. //for loop to jump the incrament of letters from length of realStr
  56. for (int position = 0 ; position < realStr.length () ; position++)
  57. {
  58. char character2 = realStr.charAt (position);
  59. int character2Pos = realStr.indexOf (character2);
  60. //for loop to build the final cipher alphabet
  61. for (int index = character2Pos ; index >= realStr.length () ;
  62. index += realStr.length ())
  63. {
  64. realStr += realStr.charAt (index);
  65. }
  66. }
  67. return realStr;
  68. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 812
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: Cipher ALphabet Arranging help

 
0
  #2
Apr 17th, 2008
What's your definition of the cipher alphabet as opposed to the secret code? I thought that a cipher was a type of code, so I don't really understand what you are asking here...
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 1753 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC