/*Title: Encrypt.c * Version 2.0 * A Lite Encryption program packed with features * Programmer: Scott Kidder Date: 3/10/96 */ #include #include #include #include #include #include #include char password[20], user_pass[20], new_one[20], new_two[20], in_name[80], out_name[80], file_time[9], file_date[9], view_file[30], ch, path[20], source[20]; int result, choice, en_files, de_files, i, b, quantity, select, box, scooter, done = 0; FILE *input, *input_file, *output_file, *output; typedef struct one{ char original[30], altered[30], dat[9], tim[9]; }rec; rec encrypted[100], decrypted[100]; void view(){ clrscr(); printf("*****************************************************\n"); printf("Please enter the name of the file to view: "); scanf("%s",view_file); printf("*****************************************************\n"); printf(" %s\n",view_file); input_file = fopen(view_file, "r"); for(ch = getc(input_file); ch != EOF; ch = getc(input_file)) { printf("%c",ch); } printf("Press any key to continue......\n"); cin.get(ch); } void encrypt_records(){ clrscr(); input = fopen("en_quant.dat","r"); fscanf(input, "%d", &en_files); fclose(input); input = fopen("en.dat","r"); for(i = 0;i < en_files;i++){ fscanf(input, "%s\n",encrypted[i].original); fscanf(input, "%s\n",encrypted[i].altered); fscanf(input, "%s\n",encrypted[i].dat); fscanf(input, "%s\n",encrypted[i].tim); } fclose(input); b = 0; printf("*****************************************************\n"); printf("Encrypted Records\n"); printf("*****************************************************\n"); for(i = 0;i < en_files;i++){ if (b==2){ printf("Press any key......\n"); printf("-----------------------------------------------------\n"); getch(); b = 0; } b++; printf("Original file: %s\n", encrypted[i].original); printf("Encrypted file: %s\n", encrypted[i].altered); printf("Date: %s\n", encrypted[i].dat); printf("Time: %s\n", encrypted[i].tim); printf("-----------------------------------------------------\n"); } printf("Press any key to continue......\n"); cin.get(ch); } void decrypt_records(){ clrscr(); input = fopen("de_quant.dat","r"); fscanf(input, "%d", &de_files); fclose(input); input = fopen("de.dat","r"); for(i = 0;i < de_files;i++){ fscanf(input, "%s\n",decrypted[i].original); fscanf(input, "%s\n",decrypted[i].altered); fscanf(input, "%s\n",decrypted[i].dat); fscanf(input, "%s\n",decrypted[i].tim); } fclose(input); b = 0; printf("*****************************************************\n"); printf("Decrypted Records\n"); printf("*****************************************************\n"); for(i = 0;i < de_files;i++){ if (b==2){ printf("Press any key......\n"); printf("-----------------------------------------------------\n"); getch(); b = 0; } b++; printf("Original file: %s\n", decrypted[i].original); printf("Decrypted file: %s\n", decrypted[i].altered); printf("Date: %s\n", decrypted[i].dat); printf("Time: %s\n", decrypted[i].tim); printf("-----------------------------------------------------\n"); } printf("Press any key to continue......\n"); cin.get(ch); } void password_entry(void){ input = fopen("dat.dat","r"); i = 0; for(ch = getc(input); ch != EOF; ch = getc(input)) { ch = ch + 5; password[i] = ch; i++; } fclose(input); do{ printf("Enter your password: "); /*scanf("%s",user_pass); */ for(i = -1; ch == '\r'; user_pass[i] = ch){ i++; ch = getch(); printf("*"); } result = strcmp(user_pass, password); if(result != 0) printf("Password Invalid - Please Re-enter\n"); }while(result != 0); choice = 0; } void encode(void){ do{ clrscr(); scooter = 0; strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ path[0] = 'A' + getdisk(); /* replace X with current drive letter */ getcurdir(0, path+3); /* fill rest of string with current directory */ printf(" Current Directory: %s\n", path); printf(" Commands\n"); printf(" (cd)=change directory, (md)=make directory, (q)=quit\n"); printf("*******************************************************\n"); printf("Enter command or filename: "); scanf("%s", in_name); if(0 == strcmp(in_name, "cd")){ printf("*******************************************************\n"); printf("Enter name of directory: "); scanf("%s", in_name); chdir(in_name); clrscr(); scooter = 1; } if(0 == strcmp(in_name, "md")){ printf("*******************************************************\n"); printf("Enter name of new directory: "); scanf("%s", in_name); mkdir(in_name); clrscr(); scooter = 1; } if(0 == strcmp(in_name, "q")){ scooter = 1; } /* for (scanf("%s",in_name); (input_file = fopen(in_name,"r")) == NULL; scanf("%s", in_name)) { printf("Cannot open %s for input\n",in_name); printf("Re-Enter file name: "); } */ if(scooter == 0) { printf("Enter the name for the encoded copy: "); scanf("%s",out_name); input_file = fopen(in_name, "r"); output_file = fopen(out_name, "w"); for(ch = getc(input_file); ch != EOF; ch = getc(input_file)) { ch = ch+5; putc(ch,output_file); } _strtime(file_time); _strdate(file_date); fclose(input_file); fclose(output_file); chdir(source); input = fopen("en_quant.dat","r"); fscanf(input,"%d",&quantity); fclose(input); quantity = quantity + 1; output = fopen("en_quant.dat", "w"); fprintf(output,"%d",quantity); fclose(output); output = fopen("en.dat","a"); fprintf(output,"%s\n",in_name); fprintf(output,"%s\n",out_name); fprintf(output,"%s\n",file_date); fprintf(output,"%s\n",file_time); fclose(output); done = 1; } }while(0 != strcmp(in_name, "q")); } void decode(void){ do{ clrscr(); scooter = 0; strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ path[0] = 'A' + getdisk(); /* replace X with current drive letter */ getcurdir(0, path+3); /* fill rest of string with current directory */ printf(" Current Directory: %s\n", path); printf(" Commands\n"); printf(" (cd)=change directory, (md)=make directory, (q)=quit\n"); printf("*******************************************************\n"); printf("Enter command or filename: "); scanf("%s", in_name); if(0 == strcmp(in_name, "cd")){ printf("*******************************************************\n"); printf("Enter name of directory: "); scanf("%s", in_name); chdir(in_name); clrscr(); scooter = 1; } if(0 == strcmp(in_name, "md")){ printf("*******************************************************\n"); printf("Enter name of new directory: "); scanf("%s", in_name); mkdir(in_name); clrscr(); scooter = 1; } if(0 == strcmp(in_name, "q")){ scooter = 1; } /*printf("Enter the name of the file you want to decode: "); for (scanf("%s",in_name); (input_file = fopen(in_name,"r")) == NULL; scanf("%s", in_name)) { printf("Cannot open %s for input\n",in_name); printf("Re-Enter file name: "); } */ if(scooter == 0){ printf("Enter the name for the decoded copy: "); scanf("%s",out_name); input_file = fopen(in_name, "r"); output_file = fopen(out_name, "w"); for(ch = getc(input_file); ch != EOF; ch = getc(input_file)) { ch = ch-5; putc(ch,output_file); } _strtime(file_time); _strdate(file_date); fclose(input_file); fclose(output_file); chdir(source); input = fopen("de_quant.dat","r"); fscanf(input,"%d",&quantity); fclose(input); quantity = quantity + 1; output = fopen("de_quant.dat", "w"); fprintf(output,"%d",quantity); fclose(output); output = fopen("de.dat","a"); fprintf(output,"%s\n",in_name); fprintf(output,"%s\n",out_name); fprintf(output,"%s\n",file_date); fprintf(output,"%s\n",file_time); fclose(output); } }while(0 != strcmp(in_name, "q")); } void change(void){ clrscr(); do{ printf("-------------------------------------\n"); printf("Enter your new password: "); scanf("%s",new_one); printf("Re-enter to verify: "); scanf("%s",new_two); result = strcmp(new_one, new_two); if(result != 0) printf("You screwed up! Please start over again\n"); }while(result != 0); i = 0; do{ new_one[i] = new_one[i] - 5; i++; }while(new_one[i] != NULL); input = fopen("dat.dat","w"); fprintf(input,"%s",new_one); fclose(input); } main(void){ strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ path[0] = 'A' + getdisk(); /* replace X with current drive letter */ getcurdir(0, path+3); /* fill rest of string with current directory */ strcpy(source, path); clrscr(); password_entry(); do{ clrscr(); printf("Scott Kidder Software's Encryption Lite\n"); if(choice > 6){ printf("This time, choose an option that exists, Okay?!\n"); printf("-------------------------------------\n"); } printf("*********************Menu*******************\n"); printf("1.) Encode\n"); printf("2.) Decode\n"); printf("3.) Change your password\n"); printf("4.) View Encode/Decode records\n"); printf("5.) View Text files\n"); printf("6.) Quit (How Dare you even think about it!)\n"); printf("********************************************\n"); printf("Enter the number of your corresponding choice: "); scanf("%d",&choice); if(choice==1){ encode(); } if(choice==2){ decode(); } if(choice==3){ change(); } if(choice==4){ do{ printf("---------------------------------------\n"); printf("1.) Encoded Records\n"); printf("2.) Decoded Records\n"); printf("---------------------------------------\n"); printf("Enter your selection: "); scanf("%d",&select); if(select==1) encrypt_records(); if(select==2) decrypt_records(); }while(select>2); } if(choice==5){ view(); } }while(choice<6); }