artichoke cipher only using first letter of word
<p>my artichoke cipher will only use the first letter of my keyword "montypython" in my code when i want it to apply each letter to each line of text so thomas would be like
thomas
montyp</p>

<p>so the first letter "t" would be shifted by the "m" and the second letter by the "o" and so on but it is only using my first letter.</p>

<p>how can i get the cipher to use all of the characters instead of just the m?</p>

<p>Please help :(</p>

<p>Thanks, Collin</p>

<pre><code>import java.util.Scanner;
import java.io.*;

public class ArtichokeCipher {

    public static void main(String[] args) throws IOException {
        Scanner scan1 = new Scanner(System.in);

        System.out.println("Welcome to Artichoke Cipher!");
        System.out.println("Please name input file to be processed: ");
        String filei = scan1.next();
        Scanner scan = new Scanner(new File(filei));

        System.out.println("Please enter the word to be used as the cipher key: ");
        String shift = scan1.next();


        for (int j = 0; j &lt; shift.length(); j++) {
            int realch = 0;
            int key = (shift.charAt(j));
            if (key &lt;= 'z' &amp;&amp; key &gt;= 'a') {
                realch = realch + ((int) (shift.charAt(j) - 97));
            } else if (key &gt;= 'A' &amp;&amp; key &lt;= 'Z') {
                realch = realch + ((int) (shift.charAt(j) - 65));
            }

            while (scan.hasNext()) {
                String word = scan.nextLine();
                String answer = "";

                for (int i = 0; i &lt; word.length(); i++) {
                    int loc = word.charAt(i) + realch;
                    if (loc &gt; 'z') {
                        answer = answer + (char) (word.charAt(i) + realch - 26);
                    } else if (loc &gt; 'Z' &amp;&amp; loc &lt; 'a') {
                        answer = answer + (char) (word.charAt(i) + realch - 26);
                    } else if (word.charAt(i) == ' ') {
                        answer = answer + (word.charAt(i));
                    } else {
                        answer = answer + (char) (word.charAt(i) + realch);
                    }
                }
                System.out.println("Encoded: " + answer);
            }
        }
    }
}
</code></pre>
