runee1000 0 Newbie Poster

Hi: I need help with a program. Basically, I have a sentence, which I need to distribute into blocks of 5 letters, and then scramble the blocks in an order which I determine. Here is the exact question:

"Fixed period encryption- Given the number d and the numbers 1 to d in some order, take the blocks of d characters from the plain text and re-arrange the characters according to the order given. Ignore spaces, change all the characters to lower case and if the last grouping does not contain d characters, fill it with @ symbols. For example, if d = 5 and the order is (4,2,3,1,5), then "I like spinach salad" becomes "kliie npisa ahscl @d@a@"

With what I have right now, I managed to get a sentence, and distribute it into blocks 5. Now I need to scramble the words. Its not that I do not know what to use or do, but I'm totally lost so if you could write some code to assist me, that would help greatly, since I am a complete beginner at java. Since my knowledge is very limited as of right now, I do not know how to initiate concepts such as arrays, among other things which might make this project easier. My teacher said to use string methods such as s.indexOf, s.charAt, s.substring which may help, but I still need help with the project. Please assist me in this and thanks very much.

And now for the code:

/**
 * AWT Sample application
 *
 * @author 
 * @version 1.00 09/11/04
 */
public class scramble {
    public static void main(String[] args)
    {
    	String s = "these programs encrypt";
    	String e = "";
    	
  			String tmp = "";
  		int x = 1;
  		int d = 5;
//  		block = s.substring(d);
  			for (int i = 0; i < s.length(); i++)
  			{
  				if (s.charAt(i) != ' ')
  				{
  					tmp += s.charAt(i);
  					x++;
  				}
  				if (x>d)
  				{
  					tmp += ' ';
  					x = 1;
  				}
  			
  			
  			
  		
  			}
  			System.out.println(tmp);
  			}
//  			 block1 = s.substring("d");
  		//	for(int i = 0; i<block1.length; i++)
  		//	{
  		//		block1.indexOf("t");
  			//}
  			}

anything with // notes are things which I put in // so that the program would run showing the distribution of the sentence into 5 letter blocks.

Thanks for all your help guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.