Sunday, November 16, 2008

CYPHER program in C

/* This program was made by SAURABH MAHESHWARI & HRUSHIKESH ZADGAONKAR
on 13'th nov,2008 as mini-project
 CYPHER 
*/# include "conio.h"

# include "stdio.h"

# include "stdlib.h"

# include "ctype.h"

void main()

{

clrscr();

int i,j;

FILE *source_file,*first_encrypt,*second_encrypt,*third_encrypt;

char a;

source_file=fopen("s.txt","r"); //sorce file is opened in read only mode.

first_encrypt=fopen("s1.txt","w+"); //first destination file is opened.

second_encrypt=fopen("s2.txt","w+"); //second destination file is opened.

third_encrypt=fopen("s3.txt","w"); //Third destination file is opened. printf("******************************* CYPHER *******************************\n"); printf("\n\n\n\nGiven File Contents are : \n");
//This While loop is checking that source file contains alphabets only //Printing the source file contents to the console
while (1) { a=fgetc(source_file); if(a==EOF) break; else { if ((a<65>122 || (a>90 && a<97)) && a!=32) { printf("\n\n\nÞ Please check...File contains Invalid character after this wordÞ "); fclose(source_file); goto A; } else { printf("%c",a); } } } printf("\n\nFirst encrypted File Contents are :\n");
fseek(source_file,0,SEEK_SET); //File pointer is set to initial position
//This while loop is giving the first encryption A to C and so on...
while (1) { a=fgetc(source_file); if (a==EOF) break; else { if (a!=32) { a=toupper(a); for(i=0;i<2;i++) { a=a+1; if (a==91) a=65; } fputc(a,first_encrypt); } else fputc(a,first_encrypt); printf("%c",a); } } printf("\n\nThe Second Encrypted File Contents are :\n"); fclose(source_file); // Closing the source file
fseek(first_encrypt,0,SEEK_SET); //File pointer is set to initial

//This While Loop Gives 2nd Encrypted File Contents
while (1) { a=fgetc(first_encrypt); if (a==EOF) break; else { if (a!=32) { for (i=0;i<3;i++) { a=a-1; if (a==64) a=90; } fputc(a,second_encrypt); } else fputc(a,second_encrypt); printf("%c",a); } }
printf("\n\nThe Third File Encrypted Contents are : \n");
fclose(first_encrypt); //Closing First File
fseek(second_encrypt,0,SEEK_SET); //Setting File Pointer to initial
//This While Loop Gives 3rd Encrypted File Contents
while (1) { a=fgetc(second_encrypt); if (a==EOF) break; else { if (a!=32) {
for (i=0;i<12;i++) { a=a+1; if (a==91) a=65; }
fputc(a,third_encrypt); } else fputc(a,third_encrypt); printf("%c",a); } }
A:
fclose(second_encrypt); //Closing Second File
fclose(third_encrypt); //Closing Third File
printf(" \n\n\n\n\n\n\n\n  SAURABH and HRUSHIKESH  ");getch();
}

No comments: