 
/*                  ENCRYPTOR                     */
/*      Compute!'s Atari ST Disk & Magazine           */
/*        October 1986 -- Volume 1, No. 1                 */
/*        = 1986 Compute Publications/ABC                 */
 
 
#include <stdio.h>
#include <osbind.h>
 
main()
  {
        int   i = 0, c1;
 
        char  password[40], filename[40], c;
        FILE  *fopen (), *file_ptr1, *file_ptr2;
 
        printf ( "What is the name of the file to be CRYPTed? " );
        scanf  ( "%s", filename ); printf ( "\n" );
        printf ( "What is the PASSWORD to be used? ");
        scanf  ( "%s", password ); printf ( "\n" );
 
        file_ptr1 = fopen ( filename, "r" );
 
        if ( file_ptr1 == NULL)
          {
                printf ( "Couldn't open %s for input.\n", filename );
                getchar();
          }
        else
          {
                file_ptr2 = fopen ( "qqqq", "w" );
 
                if ( file_ptr2 == NULL )
                  {
                        printf ( "Couldn't open output file.\n" );
                        getchar();
                  }
                else
                  {
                        while ( ( c = fgetc ( file_ptr1 ) ) != EOF )
                          {
                                c1 = password[i] * 2 - c;
                                if ( c1 > 255 )
                                  c1 -= 256;
                                if ( c1 < 0 )
                                  c1 += 256;
 
                                fputc ( c1, file_ptr2 );
 
                                ++i;
                                if ( password[i] == '\0' )
                                  i = 0;
                          }
 
                        fclose ( file_ptr1 );
                        fclose ( file_ptr2 );
 
                        Fdelete ( filename );
                        Frename ( 0,"qqqq", filename );
                  }
          }
  }
