title: OpenSSL ECB non 64 bits multiple plain text
body: <p>I'm having problems when I try to cipher and decipher a non 64 bits multiple plain text using OpenSSL ECB problem.</p>
  
  <p>I have two .c files, one to cipher, another one to decipher. </p>
  
  <p>This is the first one.</p>
  
  <pre><code>// FILE ENCRYPTION
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;openssl/des.h&gt;
  #include &lt;sys/types.h&gt;
  
  void merror(char *msg) {
    perror(msg);
    exit(0);
  }
  
  char *Encriptar(char *Key, char *Msg, int size) {
    static char*    Res;
    int       n=0;
    DES_cblock      Key2;
    DES_key_schedule schedule;
    Res = ( char * ) malloc( size );
  
    memcpy( Key2, Key,8);
    DES_set_odd_parity( &amp;Key2 );
    DES_set_key_checked( &amp;Key2, &amp;schedule );
    DES_ecb_encrypt((unsigned char *)Msg, (unsigned char *)Res, &amp;schedule,DES_ENCRYPT);
    return (Res);
  }
  
  #define LINELEN 8
  
  int main(int argc, char *argv[]) {
    int n, fdp, fdc;
    char key[]="password";
    unsigned char buf[LINELEN];
  
    if (argc &lt; 3) {fprintf(stderr,"USO %s &lt;fileP&gt; &lt;fileC&gt;\n",argv[0]);exit(0);}
    if ((fdp = open (argv[1], O_RDONLY)) == -1)
       merror ("Open FDP");
     if ((fdc = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 00744)) == -1)
        merror ("Open FDC");
     while ((n = read(fdp, buf, LINELEN)) &gt; 0) 
     write (fdc, Encriptar(key, buf, n), n);
  
     close (fdp);
     close (fdc);
     exit (0);
  }
  </code></pre>
  
  <p>This is the second one</p>
  
  <pre><code>//FILE DECRYPTION
  
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;openssl/des.h&gt;
  #include &lt;sys/types.h&gt;
  
  void merror(char *msg) {
    perror(msg);
    exit(0);
  }
  
  char *Decriptar(char *Key, char *Msg, int size) {
    static char* Res;
    int n=0;
    DES_cblock      Key2;
    DES_key_schedule schedule;
    Res = ( char * ) malloc( size );
    memcpy( Key2, Key,8);
    DES_set_odd_parity( &amp;Key2 );
    DES_set_key_checked( &amp;Key2, &amp;schedule );
    DES_ecb_encrypt((unsigned char *)Msg, (unsigned char *)Res,&amp;schedule,DES_DECRYPT);
    return (Res);
  }
  
  #define LINELEN 8
  int main(int argc, char *argv[]) {
  int n, fdp, fdc;
  char key[]="password";
  unsigned char buf[LINELEN];
  
  if (argc&lt;3) {fprintf(stderr,"USO %s &lt;fileC&gt; &lt;fileP&gt;\n", argv[0]); exit(0);}
  
  if ((fdc = open (argv[1], O_RDONLY)) == -1)
  merror ("Open FDP");
  if ((fdp = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 00744)) == -1)
  merror ("Open FDC");
  
  while ((n = read(fdc, buf, LINELEN)) &gt; 0) 
  write (fdp, Decriptar(key, buf, n), n);
  
  close (fdp);
  close (fdc);
  
  exit (0);
  }
  </code></pre>
  
  <p>But, the plain text I got from the decipher es not the same as the plain text I used to create mi cipher text.</p>