944,099 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 329
  • Java RSS
Nov 7th, 2009
0

Fixed Period Encryption

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  1. /**
  2.  * AWT Sample application
  3.  *
  4.  * @author
  5.  * @version 1.00 09/11/04
  6.  */
  7. public class scramble {
  8. public static void main(String[] args)
  9. {
  10. String s = "these programs encrypt";
  11. String e = "";
  12.  
  13. String tmp = "";
  14. int x = 1;
  15. int d = 5;
  16. // block = s.substring(d);
  17. for (int i = 0; i < s.length(); i++)
  18. {
  19. if (s.charAt(i) != ' ')
  20. {
  21. tmp += s.charAt(i);
  22. x++;
  23. }
  24. if (x>d)
  25. {
  26. tmp += ' ';
  27. x = 1;
  28. }
  29.  
  30.  
  31.  
  32.  
  33. }
  34. System.out.println(tmp);
  35. }
  36. // block1 = s.substring("d");
  37. // for(int i = 0; i<block1.length; i++)
  38. // {
  39. // block1.indexOf("t");
  40. //}
  41. }
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
runee1000 is offline Offline
10 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: problem with date class
Next Thread in Java Forum Timeline: JavaFX question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC