/* this program is meant to decrypt files and convert them to ebcidic
                  it is meant to work in conjuction with a similar set
   of programs on the unix side  - S. Thorne 1/28/92 */
 
# include <bsdtypes.h>
# include <stdio.h>
# include <string.h>
# include <des.h>
#include <des_ext>
#include  <fcntl.h>
#include  <error.h>
#include  <bsdtocms.h>
 
#pragma  linkage(CMXLATE,OS)
extern char ebcdicto;
extern char asciitoe;
#define buflen 1024 /* don't change this without also changing it on
                       the unix side */
des_cblock           my_cblok;
 
Key_schedule      key_schd;
char unsigned     ivec[buflen];
 
FILE *o,*i,*m;
char  buf[buflen + 1000];
char  output[buflen + 1000];
 
 
main(ac,av)
int ac;
char *av[];
{
 
char ebc_str[30];
char in_file[30],*end,*ptr;
char out_file[30],*cp,*start,test[500];
int  x,thelen,ln;
size_t  num,len,rc;
if (ac < 5) {
printf("You must enter the input and output file name and type\n");
printf("as well as the length of the record\n");
exit(); }
sprintf(in_file,"%s.%s",av[1],av[2]);
sprintf(out_file,"%s.%s",av[3],av[4]);
printf("infile %s\n",in_file);
printf("outfile %s\n",out_file);
m =fopen(in_file      ,"rb");
o =fopen(out_file    ,"w");
if (!m|!o){
  printf("file wasn't opend\n");exit(); }
printf("Password:\n");  /* should be using des_read_password, but it
                      does not work under current release */
fflush(stdout);
gets(ebc_str);
des_string_to_key(ebc_str,my_cblok);
des_key_sched(my_cblok ,    key_schd );
while (!feof(m))
{
 rc = fread(buf,sizeof(char),buflen,m);
   start = output;
   des_cbc_encrypt(buf, output, rc     , key_schd , ivec, DES_DECRYPT);
       CMXLATE(output,&asciitoe,rc);
       strncpy(test,output,90);
       num = 0;
       for (cp = output; num < buflen; cp++,num++)  {
         if (*cp ==  0x25 )  {  /* found a newline */
           *cp= '\0';
           sprintf(test,"%s\n",start);
           fputs(test ,o);
           start = cp + 1;
          }
       }
   } /* end of while */
fclose( o);
fclose( m );
}
 
 
 
 
