title: shift array elements to left in java
body: <p>I am writing the SDES cipher in java, getting to the stage where I am shifting two arrays of length 5 one space to the left, this works fine for p10kleft to become shiftp10kleft, but when I apply the same code to p10kright to become shiftp10kright it adds a random 1 at the end instead of shifting the first 0 to become the last bit.</p>
  
  <p>HERE IS MY CODE:</p>
  
  <pre><code>package ciphers;
  import java.io.*;
  import java.lang.reflect.Array;
  import java.util.Arrays;
  import java.util.Collections;
  
  public class SDESNew {
  
      public static void main(String []arg)throws Exception
      {
          int[] k = {1,1,1,1,0,1,1,0,0,0};
          int[] P10 = {3,5,2,7,4,10,1,9,8,6};
          int[] P8 = {6,3,7,4,8,5,10,9};
          int[] P4 = {2,4,3,1};
          int[] IP = {2,6,3,1,4,8,5,7};
          int[] EP = {4,1,2,3,2,3,4,1};
          int S0[][] = {
                          {1,0,3,2},
                          {3,2,1,0},
                          {0,2,1,3},
                          {3,1,3,2}
                      };
  
          int S1[][] = {
                          {0,1,2,3},
                          {2,0,1,3},
                          {3,0,1,2},
                          {2,1,0,3}
                      };
  
          //Arrays that we have to calculate
          int p10k[]=new int[10]; //Create p10(k) array
          int[] p10kleft = new int[5];
          int[] p10kright = new int[5];
          int[] shiftp10kleft = new int[5];
          int[] shiftp10kright = new int[5];
  
  
  
          for(int i=0;i&lt;10;i++)
          {
              System.out.println("Value from array P10: " +P10[i]);                           //Printing values from array P10
              System.out.println("Array position to be used in array k: "     +(P10[i]-1)); //Array position begins at 0 so subtracting 1 from P10 position so array begins at 0
              System.out.println(k[P10[i]-1]); //Printing values in array positions
              p10k[i]=k[P10[i]-1]; //Putting array values in p10k array
              System.out.println("");
          }
          System.out.println("P10k: " +Arrays.toString(p10k)); //Printing out all values in p10k array
  
           System.arraycopy(p10k, 0, p10kleft, 0, p10kleft.length);
           System.arraycopy(p10k, p10kleft.length, p10kright, 0, p10kright.length);
  
           System.out.println("Left: " +Arrays.toString(p10kleft));
           System.out.println("Right: " +Arrays.toString(p10kright));
  
  
  
          // System.arraycopy(p10kleft, 1, shiftp10kleft, 0, p10kleft.length - 1);
  
           int n = p10kleft.length;
           shiftp10kleft = p10kleft;
           int i = 0;
           if (n&gt;0)
           {
               for(i=0; i&lt;n-1; i++)
               {
                   p10kleft[i]=p10kleft[i+1];
               }
           }
           p10kleft[i] = shiftp10kleft[i];
  
  
           System.out.println("Shift Left: " +Arrays.toString(shiftp10kleft));
  
  
  
  
           n  = p10kright.length;
           shiftp10kright = p10kright;
           i = 0;
           if (n&gt;0)
           {
               for(i=0; i&lt;n-1; i++)
               {
                   p10kright[i]=p10kright[i+1];
               }
           }
           p10kright[i] = shiftp10kright[i];
  
  
           System.out.println("Shift Right: " +Arrays.toString(shiftp10kright));
  
  
          } 
  
          }
  </code></pre>
  
  <p>HERE IS THE CURRENT OUTPUT:</p>
  
  <pre><code>Value from array P10: 3
  Array position to be used in array k: 2
  1
  
  Value from array P10: 5
  Array position to be used in array k: 4
  0
  
  Value from array P10: 2
  Array position to be used in array k: 1
  1
  
  Value from array P10: 7
  Array position to be used in array k: 6
  1
  
  Value from array P10: 4
  Array position to be used in array k: 3
  1
  
  Value from array P10: 10
  Array position to be used in array k: 9
  0
  
  Value from array P10: 1
  Array position to be used in array k: 0
  1
  
  Value from array P10: 9
  Array position to be used in array k: 8
  0
  
  Value from array P10: 8
  Array position to be used in array k: 7
  0
  
  Value from array P10: 6
  Array position to be used in array k: 5
  1
  
  P10k: [1, 0, 1, 1, 1, 0, 1, 0, 0, 1]
  
  Left: [1, 0, 1, 1, 1]
  
  Right: [0, 1, 0, 0, 1]
  
  Shift Left: [0, 1, 1, 1, 1]
  
  Shift Right: [1, 0, 0, 1, 1]
  </code></pre>
  
  <hr>
  
  <p>I need Shift Right to correctly output [1, 0, 0, 1, 0]</p>