title: When encrypting 2 Strings with XOR in Java, what is key[i % key.length]
body: <p>I'm trying to understand "encrypting" 2 Strings with XOR in Java, I've found <a href="https://github.com/KyleBanks/XOREncryption/blob/master/Java%20(Android%20compatible)/XOREncryption.java#L7" rel="nofollow noreferrer">pretty clear example</a> but I can't understand why they are doing this:</p>
  
  <pre><code>input.charAt(i) ^ key[i % key.length]
  </code></pre>
  
  <p>How in "human readable way" to descirbe <code>key[i % key.length]</code>, e.g. they are taking next chat from input and XOR-ing it with ...?</p>
  
  <p>Whole method for "encrypting" with XOR is:</p>
  
  <pre><code>private static String encryptDecrypt(String input) {
      char[] key = {'K', 'C', 'Q'}; //Can be any chars, and any length array
      StringBuilder output = new StringBuilder();
  
      for(int i = 0; i &lt; input.length(); i++) {
          output.append((char) (input.charAt(i) ^ key[i % key.length]));
      }
  
      return output.toString();
  }
  </code></pre>