/* this is a program designed to work with a program on CMS which decrypts
  data files S. Thorne */

# include <stdio.h>
# include <string.h>
# include <des.h>
#include  <sys/file.h>
#include <sys/types.h>
#include <netinet/in.h>
#define buflen 1024 /* don't change this without also making changes on the 
		       CMS side */

main(argc,argv)
int argc;
char *argv[];
{
des_cblock        my_cblock;
Key_schedule      my_key_schedule;
char unsigned     ivec[buflen];
int o,i,len,x;
char  buf[buflen];
char  newbuf[buflen];

if (argc < 3) {
  printf("you must give an input and output filename\n"); exit(); }

i = open(argv[1],O_RDONLY);
o = open(argv[2],O_WRONLY|O_CREAT,0644);

des_read_password( my_cblock,"Passwd:",0);
des_key_sched(my_cblock, my_key_schedule);

while ((len = read(i,buf, buflen)) != NULL)
{
    des_cbc_encrypt (buf, newbuf, len, my_key_schedule, ivec, DES_ENCRYPT);
    x = len%8;
    if (x!=0)
      len = len + 8 -x; /*routines pad to 8 byte multiples */
    write(o,newbuf,len);
}
if (x!=0)
     printf("%d Extra bytes!!\n",8-x);
close ( o);
close ( i);
}




