
Untitled
By: a guest on
May 25th, 2012 | syntax:
C++ | size: 1.03 KB | hits: 16 | expires: Never
#include <stdio.h>
int encrypt();
int decrypt();
int main(){
int choice=0;
while(choice == 0){
printf("\nWhat would you like to do?\n");
printf("1. Encrypt\n2. Decrypt\n3. Exit\n");
printf("Option: ");
scanf("%d", &choice);
if (choice == 1)
choice = encrypt();
if (choice == 2)
choice = decrypt();
if (choice == 3)
return 0;
}
return 0;
}
int encrypt(){
char buffer[BUFSIZ];
printf("\n\nInput: ");
int i=0;
char c;
fflush(stdin);
while((c=getchar()) !='\n'){
buffer[i++] = c+13;
}
buffer[i] = '\0';
FILE * Output;
Output = fopen("encrypt.txt", "w+");
fprintf(Output, buffer);
fclose(Output);
return 0;
}
int decrypt(){
char buffer[BUFSIZ];
int i=0;
char c;
FILE * Input;
Input = fopen("encrypt.txt", "r");
while((c=fgetc(Input))!=EOF){
buffer[i++]= c - 13;
}
buffer[i] = '\0';
printf("\n%s\n", buffer);
fclose(Input);
return 0;
}