title: Vigenere Square Decryption in C
body: <p>I'm trying to encrypt and decrypt a message using a passphrase and a vigenere square stored in an array. I am able to encrypt the message successfully however I can't work out how to decrypt it again afterwards. Any ideas? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  void encrypt(char *text, char *pass, int n, int m, char *vs);
  void decrypt(char *text, char *pass, int n, int m, char *vs);
  void vigsq(char *vs);
  
  main()
  {
       char text[] = "HELLOWORLD";
       char pass[] = "MAGIC";
       int n, m;
       char vs[26*26];
       char *vsPointer, *textPointer, *passPointer;
       char command;
       char inputfile[10];
       char outputfile[10];
       //printf("Please enter e/d, pass phrase, input file, output file:");
       //scanf("%c, %s, %s, %s", &amp;command, &amp;pass, &amp;inputfile, &amp;outputfile);
       vsPointer = vs;
       textPointer = text;
       passPointer = pass;
       vigsq(vsPointer);
       //printf("%c, %s, %s, %s\n", command, pass, inputfile, outputfile);
  
      n = strlen(text);
      m = strlen(pass);
      //printf("%d, %d", n, m);
      encrypt(textPointer, passPointer, n, m, vsPointer);
      printf("%s\n", text);
      decrypt(textPointer, passPointer, n, m, vsPointer);
      printf("%s\n", text);   
  }
  
  void encrypt(char *text, char *pass, int n, int m, char *vs)
  {
      int i;
      int ascii1;
      int ascii2;
      int passcount = 0;
      char encrypt;
      for (i = 0; i &lt; n; i++)
      {
          ascii1 = (int)text[i];
          ascii2 = (int)pass[passcount];
          ascii1 = ascii1 - 64;
          ascii2 = ascii2 - 64;
          encrypt = vs[((ascii1 -1)*26) + (ascii2)];
          // printf("%d, %d, %c\n", ascii1, ascii2, encrypt);
          text[i] = encrypt;
          passcount++;
          if (passcount == m)
          {
              passcount = 0;
          }
      }   
  }
  
  void decrypt(char *text, char *pass, int n, int m, char *vs)
  {
      int i;
      int ascii1;
      int ascii2;
      int passcount = 0;
      char decrypt;
      for (i = 0; i &lt; n; i++)
      {
          ascii1 = (int)text[i];
          ascii2 = (int)pass[passcount];
          ascii1 = ascii1 - 64;
          ascii2 = ascii2 - 64;
          decrypt = vs[//Don't know what to put here];
          //printf("%d, %d, %c\n", ascii1, ascii2, decrypt);
          text[i] = decrypt;
          passcount++;
          if (passcount == m)
          {
              passcount = 0;
          }
      }       
  }
  
  void vigsq(char *vs)
  {
      char alphabet[] = {'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'};
  
      int a = 0, i, j, count = 0;
      for(i = 1; i &lt;= 26*26; i++)
      {                           
          vs[i] = alphabet[a];
          a++;
          if (i % 26 == 0)
          {
              count++;
              a = count;
          }   
          if (a == 26)        
          {
              a = 0;
          }               
      }
  }
  </code></pre>
  
  <p>(Please ignore the I/O stuff I'll be implementing that later.)
  Thanks for the help :)</p>