title: C++ Program for rail fence cipher
body: <p>When I run the below program I got garbage value in str1 and str2.So </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string.h&gt;
  #include&lt;string&gt;
  using namespace std;
  
  int main()
  {
      int i,len,j=0,k=0;
      char plain[15],cip[15],str1[10],str2[10];
      cout&lt;&lt;"Enter Plain Text:";
      cin&gt;&gt;plain;
      cout&lt;&lt;endl;
      len=strlen(plain);
      for(i=0;i&lt;len;i++)
      {
          if(i%2==0)
          {
              str1[j]=plain[i];
              j++;
          }
          else
              {
                  str2[k]=plain[i];
                  k++;
              }
          }
      j=0;
  
      cout&lt;&lt;"Str1:"&lt;&lt;str1&lt;&lt;endl&lt;&lt;"Str2:"&lt;&lt;str2;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/n33Vd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n33Vd.png" alt="enter image description here"></a></p>