We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Here's the question: cryptocode accepts a string message. It will scramble the alphabet, then use it to encode the string object so that the first letter in the scrambled alphabet will replace the letter 'A', the second letter will replace the 'B's and so on (encoded string is returned).
HOW’S IT GOING? with scrambled alphabet HOAZXJRTUYBIVEWKLSNCDMFGPQ becomes
TWF'N UC RWUER?
I don't get how to replace the letters after generating the "new" alphabet
here's what i have done:
public static String cryptocode (String cryptic)
{
sc = new Scanner (System.in);
clear();
StringBuffer alphabet = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
String holder = "";
//Generates a "new" alphabet
for (int x=1; x<=100; x++)
{
char temp;
int num1 = (int)(Math.random()*alphabet.length());
int num2 = (int)(Math.random()*alphabet.length());
temp = alphabet.charAt(num1);
alphabet.setCharAt(num1, alphabet.charAt(num2));
alphabet.setCharAt(num2, temp);
}
cryptic = cryptic.toUpperCase();
System.out.println(alphabet);
for (int x= 0; x < cryptic.length(); x++)
{
//Can't figure out how to replace the letters using the new alphabet
}
return holder;
}
Answers
Thank you very much
sure!