title: encryption-decryption error(one time pad encryption)
body: <p>I fixed some problems with my old code.The problem now is when decrypting a ciphertext already encrypted with my program it gives a word with a letter different than the original one ;so word->encrypted ... then encrypted->decrypted gives decrypted!=word,and even on paper the ciphertext should be different than the one i'm getting.
  And an other thing:i tried do{...}while (strlen(...,...)!=0) but it isn't working and tried comparing sizeof also not working. How should i compare the length of the key with the word?</p>
  
  <p>Here is my new code using xor :</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #define clear_buffer while(getchar()!='\n');
  char* encrypt(char texte[],char cle[]){
      char *encrypted;
      int i=0;
      while(texte[i]!='\0' &amp;&amp; cle[i]!='\0'){
      if (texte[i] &gt;= 'A' &amp;&amp; texte[i] &lt;= 'Z')
      encrypted[i] = ((texte[i] - 'A') ^ (cle[i] - 'A')) % 26 + 'A';
  else if (texte[i] &gt;= 'a' &amp;&amp; texte[i] &lt;= 'z')
      encrypted[i] = ((texte[i] - 'a') ^ (cle[i] - 'a')) % 26 + 'a';
          i++;
      }
      encrypted[i+1]='\0';
      return encrypted;   
  
      }
  char* decrypt(char encrypted[],char cle[]){
      char *decrypted;
      int i=0;
  
      while(encrypted[i]!='\0' &amp;&amp; cle[i]!='\0'){
      if (encrypted[i] &gt;= 'A' &amp;&amp; encrypted[i] &lt;= 'Z')
      decrypted[i] = ((encrypted[i] - 'A') ^ (cle[i] - 'A')) % 26 + 'A';
  else if (encrypted[i] &gt;= 'a' &amp;&amp; encrypted[i] &lt;= 'z')
      decrypted[i] = ((encrypted[i] - 'a') ^ (cle[i] - 'a')) % 26 + 'a';
          i++;
      }
      decrypted[i+1]=0;
      return decrypted;
  
  }
  int main()
  {
      char reponse,texte[100],cle[100],encrypted[100];
      int i=0;
  
      do{
          printf("Voulez vous crypter ou decrypter un texte?(Ecrire C pour crypter et D pour decrypter)\n");
          scanf("%c",&amp;reponse);
      }while (reponse!='C'&amp;&amp; reponse!='D'&amp;&amp; reponse!='c'&amp;&amp; reponse!='d');//controle pour obliger l'utilisateur à donner c ou d
      if(reponse=='C'||reponse=='c'){
              clear_buffer;//vider le buffer apres le scanf de la reponse
                  //do{
          printf("Donner un texte a crypter\n");
          fgets(texte,100,stdin);
          while(texte[i]!=0)
              i++;
          if (i&gt;0 &amp;&amp; texte[i-1]!='\n')
              clear_buffer;
          printf("Donner une cle de meme taille\n");
          fgets(cle,100,stdin);
              //}while(sizeof texte!=sizeof cle);
          i=0;
          while(cle[i]!=0)
              i++;
          if (i&gt;0 &amp;&amp; cle[i-1]!='\n')
              clear_buffer;
          printf("Le texte crypte est:%s\n",encrypt(texte,cle));
      }else{
              clear_buffer;//vider le buffer apres le scanf de la reponse
          //  do{
          printf("Donner un texte (deja crypte) à decrypter\n");
          fgets(encrypted,100,stdin); 
          i=0;
          while(encrypted[i]!=0)
              i++;
          if (i&gt;0 &amp;&amp; encrypted[i-1]!='\n')
              clear_buffer;
          printf("Donner la cle (deja utilisee pour crypter\n");
          fgets(cle,100,stdin);
          i=0;
          while(cle[i]!=0)
              i++;
          if (i&gt;0 &amp;&amp; cle[i-1]!='\n')
              clear_buffer;
          //}while(sizeof encrypted!=sizeof cle);
          printf("Le texte decrypte est:%s\n",decrypt(encrypted,cle));
      }
      system("pause");
      return 0;
  }
  </code></pre>