title: Problem using modulo with negative numbers in decryption program
body: <p>I'm rather new to C and have recently been working on making a simple encryption/decryption program.  I managed to get the encryption fine, but I've hit a road block with the decryption.</p>
  
  <p>The relevant code is as follows:</p>
  
  <p>Encryption (where asciinum is the ascii value for the letter, and k is the "vigenere" key to be shifted by).</p>
  
  <pre><code>//shifts lowercase letters by key
      if (asciinum &gt;= 97 &amp;&amp; asciinum &lt;= 123)
      {
          f = p % keylen;
          k = key[f];
          asciinum = (asciinum - 97) + k;
          asciinum = (asciinum % 26) + 97;
          letterc = (char) asciinum;
          //printf("%c\n", letterc);
          cipher[j] = letterc;
          p++;
      }
  
      //shifts uppercase letters by key
      if (asciinum &gt;= 65 &amp;&amp; asciinum &lt;= 91)
      {
          f = p % keylen;
          k = key[f];
          asciinum = (asciinum - 65) + k;
          asciinum = (asciinum % 26) + 65;
          letterc = (char) asciinum;
          cipher[j] = letterc;
          p++;
      }
  </code></pre>
  
  <p>I want to use a similar model to decrypt (using the same key), but the modulo method I used to wrap around the 26 characters doesn't work when asciinum is negative, as would be the case in subtracting a k of 5 from a (i.e. 0).</p>
  
  <p>Decryption attempt...</p>
  
  <pre><code>    //shifts uppercase letters by key
      if (asciinum &gt;= 65 &amp;&amp; asciinum &lt;= 91)
      {
          f = p % keylen;
          k = key[f];
          asciinum = (asciinum - 65) - k;
          asciinum = (asciinum % 26) + 65;
          letterc = (char) asciinum;
          cipher[j] = letterc;
          p++;
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated.  Thanks!</p>