What am I encrypting wrong here?

Posted by Katie Krueger on Stack Overflow See other posts from Stack Overflow or by Katie Krueger
Published on 2013-10-22T20:14:17Z Indexed on 2013/10/22 21:54 UTC
Read the original article Hit count: 219

Filed under:
|
|

So I have a wordplay project to do and I have to encrypt some characters. I am at the point where I am stuck, and when I run it and type 1 for encrypt it doesn't shift that many letters. It just prints the work over again. I am wondering what I could do to fix it where if I say "hello" it will print 1 character over and say "ifmmp" Thank you!

import java.util.Scanner;

public class WordPlayTester{

    public static void main(String [] args){

    String word, reverse="";
    String original;
    int key= 0;
    String Menu= "1-Encrypt \n2-Decrypt \n3-Is Palindrome \n0-Quit \n-Select an option-";

    Scanner in = new Scanner(System.in);
    System.out.println("-Type any word-");
          word = in.nextLine();
    System.out.println(Menu);

       int choice=in.nextInt();
       if(choice==1)
       {
      System.out.println("Insert a Key number");
       int select= in.nextInt();


          for (int i=0; i < word.length(); i++) {
             char c = word.charAt(i);
             if (c >= 'A' && c <= 'Z') {
                c = (char)(c - 64);
                int n = c+1;
                n = n % 26;
                if (n < 0) {
                   n = n + 26;
                }
                c = (char)(n + 65);
             }
             System.out.println(c);
          }
          }


       else if(choice==3)
       {
       int length = word.length();
          for ( int i = length - 1 ; i >= 0 ; i-- )
             reverse = reverse + word.charAt(i);
          if (word.equals(reverse))
             System.out.println("Your word is a palindrome.");
          else
             System.out.println("Your word is not a palindrome.");


          }
          else if(choice==0)
          {
          System.exit(0);
          }

         else 
          {
          System.out.println(Menu);
          }


  }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about encryption