title: Index is outside the bound of the array
body: <p>At First I don't know which one is outside the size. And as you can see I have put % not to be outside the array. This is my code, please don't blame me for any childish mistake. If you have tips for a more efficient encrypting method I am opened</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
   using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  using System.Text;
  
  namespace encrypting
  {
      public partial class Form1 : Form
      {
      string text;
      string key;
  
      public string calcXor(string a, string b)
      {
          char[] charAArray = a.ToCharArray();
          char[] charBArray = b.ToCharArray();
          char[] result = new char[6];
          int len = 0;
  
  
  
  
          for (int i = 0; i &lt; a.Length; i++)
          {
              if (i != 0)
                  result[i] = (char) ( ((int)charAArray[a.Length % i] ^ (int)charBArray[b.Length % i]) ) ; //error
  
  
  
          }
  
          return new string(result);
      }
  
      private void Crypt()
      {
          char[] a;
          int i, sizeoftext = text.Length,j=0;
          string somestring ="";
          string key = textBox2.Text;
          StringBuilder sb = new StringBuilder(somestring);
          for(i=0;i&lt;sizeoftext-1;i++)
          {
              if (i == key.Length-1)
                  j = 0;
  
  
  
  
  
          }
          somestring = calcXor(text, key);
  
  
          if (File.Exists(textBox3.Text)) ;
          File.Create(textBox3.Text).Close();
  
          System.IO.File.WriteAllText(textBox3.Text, somestring);
  
  
  
      }
  
      public Form1()
      {
  
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  
      private void label1_Click(object sender, EventArgs e)
      {
  
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
  
  
               text = File.ReadAllText(textBox1.Text);
  
          Crypt();
  
  
      }
  
      private void textBox1_TextChanged(object sender, EventArgs e)
      {
          key = this.Text;
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
  
              OpenFileDialog fd = new OpenFileDialog();
  
              if (fd.ShowDialog() == DialogResult.OK)
              {
                  textBox1.Text = fd.FileName;
              }
  
      }
  
      private void textBox2_TextChanged(object sender, EventArgs e)
      {
  
      }
  
      private void label2_Click(object sender, EventArgs e)
      {
  
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          FolderBrowserDialog fd = new FolderBrowserDialog();
          if(fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
          {
              textBox3.Text = fd.SelectedPath;
              textBox3.Text = textBox3.Text +"\\" + textBox4.Text + ".txt";
          }
      }
  
      private void textBox4_TextChanged(object sender, EventArgs e)
      {
  
      }
  
      private void textBox3_TextChanged(object sender, EventArgs e)
      {
  
      }
  }
  }
  </code></pre>
  
  <p>Please help me.</p>