Java modulus arithmetic for string
<p>I am creating a simple Java program for my university project but i am unable to make the array string modulus. The program just takes a string and encrypts or decrypts it from +5 or -5 for the letters in the array. But if i enter any of the last 5 in the array (5,6,7,8,9) in the input string it returns nothing but it should return (a,b,c,d,e) the letters at the start of the array.</p>

<p>The program i have to use is very primivative and only allows the code to be a certain way hence why it's coded like this.</p>

<pre><code>int i;
int n;
int x;
int inputValue;
int intArrayLength;
int intInputLength;
String array;
String inputString;
String newInputString;
String outputString;

System.out.print("Would you like to: 1 = Encrypt - 2 = Decrypt");
System.in.read(inputValue);
System.out.println("Would you like to: 1 = Encrypt - 2 = Decrypt [ " + inputValue + " ]");
System.out.print("Please enter string:");
System.in.read(inputString);
System.out.println("Please enter string: [ " + inputString + " ]");

array = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
intArrayLength = length(array);
intInputLength = length(inputString);

if (intInputLength != 0)
   {
   if (inputValue == 1)
      {



      System.out.println("Please wait encrypting...");

      newInputString = "";
      for (i=0; i&lt;=intInputLength; i++)
         {
         for (n=0; n&lt;=intArrayLength; n++)
            {
            if (inputString[i] == array[n])
               {
               x = (n+5);
               if (x &gt; intArrayLength)
                  {
                  x = x - intArrayLength;
                  newInputString = newInputString + array[x];
                  }
               else
                  {
                  newInputString = newInputString + array[x];
                  }
               }
            }
         }

      System.out.print("Would you like to reverse the string? 1 = Yes - 2 = No");
      System.in.read(inputValue);
      System.out.println("Would you like to reverse the string? 1 = Yes - 2 = No [ " + inputValue + " ]");

      if (inputValue == 1)
         {
         outputString = newInputString;
         newInputString = "";
         for (i=intInputLength-1; i&gt;=0; i--)
            {
            newInputString = newInputString + outputString[i];
            }

         outputString = newInputString;
         System.out.print("Encrypted String: [ " + outputString + " ]");
         System.out.println();

         }
      else
         {
         outputString = newInputString;
         System.out.print("Encrypted String: [ " + outputString + " ]");
         System.out.println();
         }

      inputString = "";
      newInputString = "";



      }
   else
      {



      System.out.print("Has the string been reversed? 1 = Yes - 2 = No");
      System.in.read(inputValue);
      System.out.println("Has the string been reversed? 1 = Yes - 2 = No [ " + inputValue + " ]");

      if (inputValue == 1)
         {

         newInputString = "";
         for (i=intInputLength-1; i&gt;=0; i--)
            {
            newInputString = newInputString + inputString[i];
            }

         inputString = newInputString;
         }

      System.out.println("Please wait decrypting...");

      newInputString = "";
      for (i=0; i&lt;=intInputLength; i++)
         {
         for (n=0; n&lt;=intArrayLength; n++)
            {
            if (inputString[i] == array[n])
               {
               x = (n-5);
               if (x &lt;= 0)
                  {
                  x = x + intArrayLength;
                  newInputString = newInputString + array[x];
                  }
               else
                  {
                  newInputString = newInputString + array[x];
                  }
               }
            }
         }

      outputString = newInputString;
      System.out.print("Decrypted String: [ " + outputString + " ]");
      System.out.println();

      inputString = "";
      newInputString = "";



      }
   }
</code></pre>

<p>I have edited the code above. The results i am getting now after changing what "Azodious" suggested.</p>

<p>When i Encrypt "cat999" i get the result of "hfyeeef" where is the "f" coming from?
When i Decrypt "hfyeeef" i get the result of "ct995" what happened to the "a" and the "5" is the result of the additional "f" from the encrypt.</p>
