#include #include #include int encode (int, int); int encode(int ch, int key) { if (islower(ch)) { ch = (ch-'a' + key) % 26 + 'a'; ch += (ch < 'a') ? 26 : 0; } else if (isupper(ch)) { ch = (ch-'A' + key) % 26 + 'A'; ch += (ch < 'A') ? 26 : 0; } return ch; } int main (void) { FILE *file_in; FILE *file_out; char ch; char text[300]; int key; printf("Enter the name of the file you wish to see including complete pathway and file\n extension:\n"); gets(text); file_in = fopen(text,"r"); if( file_in == NULL ) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } printf("\n The contents of the file are : \n"); while( ( ch = fgetc(file_in) ) != EOF ) { printf("%c",ch); } printf("\n \n Enter the name of the file you wish to send the encryption\n to including complete pathway and file\n extension:\n"); gets(text); file_out = fopen(text,"w"); printf("\n Enter the alphabetic offset key you would like to use:"); scanf("%d", &key); while( ( ch = fgetc(file_in) ) != EOF ) { encode(ch, key); fprintf(file_out, "%c", ch); } printf("file has been encoded"); fclose(file_out); fclose(file_in); return 0;