title: How to create a substitution keyword cipher
body: <p>I am trying to develop a substitution cipher that uses a keyword to create a new cipher alphabet. I am new to Java (as I'm sure you will be able to tell!) and I am finding it 
  hard to wrap my head around the code for what I need to do. </p>
  
  <p>My understanding is as follows:</p>
  
  <p>If for example, the keyword is <code>javben</code>, I should start by finding the index of the "j"  in the plainText string array, which is 9. I then want to shift the plainText[9] into  cipherText[0] and move each other element over by 1. So the first pass of this would result in:</p>
  
  <pre><code>cipherText[] = {"j","a","b","c","d","e","f","g","h","i","k","l","m","n","o","p","q","r","s","t","u","v","w","r","x","y","z"}
  </code></pre>
  
  <p>Then I would find the "a" and it's it's already where it should be so I'll need to account for this and not shift it -- somehow. The next character is the "v" and so the process would continue.</p>
  
  <p>After shifting everything in the cipher I should end up with:</p>
  
  <pre><code>plainText []= {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","r","x","y","z"}
  cipherText[]= {"j","a","v","b","e","n","c","d","f","g","h","i","k","l","m","o","p","q","r","s","t","u","w","r","x","y","z"}
  </code></pre>
  
  <p>As you can see, I am reasonably sure that I understand the process of which to go through, however I am really struggling wrap my head around the code required for this. Help please! </p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  /**
  * This program uses a keyword for a simple substitution cipher.
  * 
  * @author Bryan
  * @version Programming Project
  */
  
  public class Cipher
  {
  // The main method removes duplicate characters in a word input by the user.
  public static void main(String[] args) throws IOException
  {
      // Creatae a new scanner object for keyboard input
      Scanner keyboard = new Scanner(System.in);
  
      // prompt the user to enter a word
      System.out.println("Please enter your keyword: ");
      // and get their input
      String input = keyboard.nextLine();
      // the keyword will be built up here
      String keyword = "";
  
      while(input.length() &gt; 0) 
      {
          // get the first letter
          char letter = input.charAt(0);
          // if the letter is not already in the output
          if (keyword.indexOf(letter) == -1)
          {
              // add it to the end
              keyword = keyword + letter;
          }
  
          // that letter is processed : discard it
          input = input.substring(1);
      }
  
      //this is just to confirm the duplicate letters in the keyword are removed
      System.out.println(keyword); 
      getFile();
  
  }
  
  /**
   * This asks the user to specify a filename which is then 
   * read into the program for enciphering
   */
  
  public static void getFile()throws IOException
  {
      // Creatae a new scanner object for keyboard input
      Scanner keyboard = new Scanner(System.in);
  
      // Get the file name
      System.out.println("Enter the file name: ");
      String filename = keyboard.nextLine();
  
      //Open the file
      File file = new File(filename);
      Scanner inputFile = new Scanner(file);
  
      // Read the lines from the file until no more are left
      while (inputFile.hasNext())
      {
          //Read the next line
          String allText = inputFile.nextLine();
  
          // Display the text
          System.out.println(allText);
      }
  
  
  
  
      //Close the file
      inputFile.close();
  
  }
  
  public static void alphabet()
  {
      String[] plainText =     {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
      String[] cipherText = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  }
  }
  </code></pre>