code: private static byte[] applyCipher(byte[] keyBytes, byte[] textBytes) {
          byte[] result = new byte[textBytes.length];
          for (int i = 0; i < result.length; i++) {
              int keyPos = i % keyBytes.length;
              result[i] = (byte) (textBytes[i] ^ keyBytes[keyPos]);
          }
          return result;
      }
docs: The same algorithm applies for enciphering or deciphering. Go through the
  text, XORing with successive bytes of the key. If you apply it twice, you
  get the original text back.