import java.util.*;
import java.io.*;class SentenceCipher1001
{
  public static void main ( String[] args )
   { 
        Scanner sc;
    
        System.out.println ( "Program Start!" );
      
        System.out.println ("Sentence Cipher");
    
        sc = new Scanner ( System.in );
        
        String sourceText;
        System.out.println ("Please enter source text: "); //eg:The quick brown fox jumps over the lazy dog
        sourceText = sc.nextLine();
        sourceText = sourceText.toLowerCase();
        
        System.out.println ( "1) Encrypt text" ); /*user's selection*/
        System.out.println ( "2) Decrypt text" ); /*user's selection*/
        System.out.println ("Choice: ");
        int choice;
        choice = sc.nextInt();
        sc.nextLine();
        
                  if (choice == 1)
        {    
                 System.out.println("Enter word to encrypt: "); //eg: bread
                 String find = sc.nextLine();
                 System.out.println("Result:");
                 char ch;
                 
                 int miss_count = 0;
                 int t_length = find.length();
                 
                       for(int i = 0; i<find.length(); i++)
                     {
                           ch = find.charAt(i);
                           int pos;
                           pos = sourceText.indexOf(ch);//the position of the word user enter in sourcetext
                           System.out.println(pos);
                           
                               char this_f = find.charAt(i);
                               if(sourceText.indexOf(this_f) == -1)  miss_count ++;
                      }
                                        
                                        System.out.println("-2");//ending with -2 
                                        System.out.println( "Information loss (%)" + (miss_count * 1.0 / t_length * 100) );    
        }
                                       if (choice == 2)
                                 {
                                        System.out.println("Enter position ( -2 to end) : "); 
                                        String find = sc.nextLine();
                                        char ch;
                                        System.out.println("Result:"); 
                                        
                                        
                                            
                                            for(int i = 0; i<find.length(); i++)
                                       {
                                              ch = find.charAt(i);
                                              int pos;
                                              pos = sourceText.indexOf(ch);//the position of the word user enter in sourcetext
                                              
                                              int number = 0;
                                              char arr[] = sourceText.toCharArray();
                                                                                            if (arr[i] == 's')
                                              {
                                                   number++;
                                              }
                                                  if (pos >= 0) 
                                                  {
                                                   System.out.print("answer:" + (i+1));
                                                  }
                                                        
                                 }       }
    }
}
                    
程序是先让用户输入字串符,然后选择加密或者解密,加密做完了。     
解密的密码就是从第一部分,也就加密那里得来的字符在字串符那里的位置,但是我不知道应该怎么逆向表达了,求各位帮帮忙