Results 1 to 4 of 4

Thread: encode decode

  1. #1
    jaki312 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default encode decode

    can any1 help me out pls im trying to make a program that when you enter any word it will move each letter in the word up by 1 like e.g a=b b=c c=d.....y=z z=a;
    if the word is longer than 3 letters the first 3 letters should go behind the word like e.g. input: hallo output: lohal encode output:mpibm
    if its les than 3 letters the first letter should come last like e.g. input: hal output:lah encode output:mbi
    i also want to decode it to its original form.
    here is code that i got so far i get it to a ascii value that is int but dont know how to change back to string and also if the program will encode correctly
    it first asks to encode the string then decode pls help
    okay so i tried to make the program in gui but it stil has problems when its longer than 3 letters both in my encode and decode program it has problems but when its less its okay so can some1 just test this out and help me pls
    if the word is longer than 3 letters it wont print out all the leters pls help me out

    encode program:
    Java Code:
     String jo = jTextField1.getText();
     int len = jo.length();
     
    
    if(len > 3)
     {
     for(int i = 3; i < len; i++)
     {
     char ch = jo.charAt(i);
     int i1 = ch + 1;
     char c = (char) i1;
     
    jTextField2.setText(""+c);
     }
     char c1 = jo.charAt(0);
     int i1 = c1 + 1;
     char cs1 = (char) i1;
     
    char c2 = jo.charAt(1);
     int i2 = c2 + 1;
     char cs2 = (char) i2;
     
    char c3 = jo.charAt(2);
     int i3 = c3 + 1;
     char cs3 = (char) i3;
     
    jTextField2.setText("" + cs1 + cs2 + cs3); 
    }
     else if (len > 2)
     {
     char c1 = jo.charAt(0);
     int i1 = c1 + 1;
     char cs1 = (char) i1;
     
    char c2 = jo.charAt(1);
     int i2 = c2 + 1;
     char cs2 = (char) i2;
     
    char c3 = jo.charAt(2);
     int i3 = c3 + 1;
     char cs3 = (char) i3;
     
    jTextField2.setText("" + cs3 + cs2 + cs1);
     }
     else if (len > 1)
     {
     char c1 = jo.charAt(0);
     int i1 = c1 + 1;
     char cs1 = (char) i1;
     
    char c2 = jo.charAt(1);
     int i2 = c2 + 1;
     char cs2 = (char) i2;
     
    jTextField2.setText("" + cs2 + cs1);
     }
     else
     {
     char c1 = jo.charAt(0);
     int i1 = c1 + 1;
     char cs1 = (char) i1;
     
    jTextField2.setText("" + cs1);
     }
    
     //end program
    
     here is decode program
    
     String jo2 = jTextField3.getText();
     int len2 = jo2.length();
     
    
    
    
    
    if(len2 > 3)
     {
     for(int i = 0; i < len2 - 3; i++)
     {
     char ch2 = jo2.charAt(i);
     int i2 = ch2 - 1;
     char c = (char) i2;
     
    jTextField4.setText(""+ c);
     }
     char cc1 = jo2.charAt(len2 - 3);
     int ii1 = cc1 - 1;
     char cs1 = (char) ii1;
     
    char cc2 = jo2.charAt(len2 -2);
     int ii2 = cc2 - 1;
     char cs2 = (char) ii2;
     
    char cc3 = jo2.charAt(len2 - 1);
     int ii3 = cc3 - 1;
     char cs3 = (char) ii3;
     
    jTextField4.setText("" + cs1 + cs2 + cs3);
     
    
    }
     else if (len2 > 2)
     {
     char cc1 = jo2.charAt(0);
     int ii1 = cc1 - 1;
     char cs1 = (char) ii1;
     
    char cc2 = jo2.charAt(1);
     int ii2 = cc2 - 1;
     char cs2 = (char) ii2;
     
    char cc3 = jo2.charAt(2);
     int ii3 = cc3 - 1;
     char cs3 = (char) ii3;
     
    jTextField4.setText("" + cs3 + cs2 + cs1);
     }
     else if (len2 > 1)
     {
     char cc1 = jo2.charAt(0);
     int ii1 = cc1 - 1;
     char cs1 = (char) ii1;
     
    char cc2 = jo2.charAt(1);
     int ii2 = cc2 - 1;
     char cs2 = (char) ii2;
     
    jTextField4.setText("" + cs2 + cs1);
     }
     else
     {
     char cc1 = jo2.charAt(0);
     int ii1 = cc1 - 1;
     char cs1 = (char) ii1;
     
    jTextField4.setText("" + cs1);
     }
    
     //end program
    can any1 tell me what i did wrong and myb corect my program making it work right pls help me out
    Last edited by Norm; 03-13-2012 at 08:59 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: encode decode

    Cross posted at Encode and Decode


    Please show the input and output from the program that shows the problem. Add some println statements that show the input and the output, execute the code and post the output here.

    Also if you want anyone to help you with testing you need to make a complete program with a class definition and a main method that compiles and executes and shows the problem.
    Last edited by Norm; 03-13-2012 at 09:04 PM.

  3. #3
    jaki312 is offline Member
    Join Date
    Mar 2012
    Posts
    7
    Rep Power
    0

    Default Re: encode decode

    yeah thats kinda where i copied it from I didnt know what those guys were talking about and im new to java and need to make an algorithm where each letter goes up by 1 but i know nothing bout that and thats the only piece of program i stumbled on thats also in netbeans

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: encode decode

    You didn't respond to this part of my post:

    Please show the input and output from the program that shows the problem. Add some println statements that show the input and the output, execute the code and post the output here.

    Also if you want anyone to help you with testing you need to make a complete program with a class definition and a main method that compiles and executes and shows the problem.

Similar Threads

  1. Replies: 1
    Last Post: 08-09-2011, 06:39 AM
  2. UTF-8 Encode?
    By FiniteRed in forum New To Java
    Replies: 1
    Last Post: 02-18-2011, 08:38 PM
  3. Encode data to torrent?
    By greatmajestics in forum AWT / Swing
    Replies: 0
    Last Post: 04-28-2010, 05:12 PM
  4. Url Encode
    By Sean_J in forum New To Java
    Replies: 0
    Last Post: 03-19-2010, 03:54 PM
  5. Getting problem in UTF-8 Encode/Decode with Java
    By sagarsway in forum Advanced Java
    Replies: 2
    Last Post: 12-22-2008, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •