Merumi 0 Newbie Poster
public class GenerateCipher
{

    /** To generate keyPhrase into cipher alphabet and secret code
    * @param keyPhrase keyPhrase to be changed
    * @return changed keyPhrase
    */
    public static String generateCipherAlphabet (String keyPhrase)
    {
        //defines the variables and creates alphabet string
        String realStr = "";

        String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String newStr = "";
        //for loop combined to delete the punctuations and spaces
        for (int index = 0 ; index < keyPhrase.length () ; index++)
        {
            char character = keyPhrase.charAt (index);
            if (Character.isLetter (character))
                newStr += character;
        }

        //for loop to remove the duplicated letters from the keyPhrase
        for (int position= 0 ; position< newStr.length () ; position++)
        {
            char removeLetter = newStr.charAt (position);
            //detects for the duplicated letters remaining in keyPhrase
            if (realStr.lastIndexOf (removeLetter, position- 1) == -1)
                realStr += removeLetter;
        }
        //starts at the end of the keyPhrase to add the alphabets
        char searchLetter = realStr.charAt (realStr.length () - 1);
        //for loop to add the alphabet starting from the searchLetter to the end
        for (int position= (alphabet.indexOf (searchLetter)) ; position< alphabet.length () ; position++)
        {
            char addLetter = alphabet.charAt (position);
            //if statement when there is a duplicated letter from the cipher
            if (realStr.lastIndexOf (addLetter, position- 1) == -1)
                realStr += addLetter;
        }
        //for loop that adds the alphabet from the beginning of keyPhrase
        for (int position= 0 ; position< alphabet.indexOf (searchLetter) ; position++)
        {
            char addLetter2 = alphabet.charAt (position);
            //if statement when there is a duplicated letter from the beginning of the cipher
            if (realStr.lastIndexOf (addLetter2) == -1)
            {
                realStr += addLetter2;

            }
        }
        //finds the length of realStr
        int lengthRealStr = realStr.length ();
        //for loop to jump the incrament of letters from length of realStr
        for (int position= 0 ; position< lengthRealStr ; position++)
        {
            char origLetter = realStr.charAt (position);
            int origLetterPos = realStr.indexOf (origLetter);
            //for loop to build the final cipher alphabet
            for (int index = origLetterPos ; index >= realStr.length () ;
                    index += lengthRealStr)
            {
                realStr += realStr.charAt (index);
            }
        }
        return realStr;
    }

PROBLEM
I don't know how to generate the secret code... meaning if the input was:

{
String origStr = "COMPUTER SCIENCE";
origStr = generateCipherAlphabet (origStr);
c.println (origStr);
}

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?