Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: C++  |  size: 1.03 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. int encrypt();
  3. int decrypt();
  4. int main(){
  5.     int choice=0;
  6.     while(choice == 0){
  7.     printf("\nWhat would you like to do?\n");
  8.     printf("1. Encrypt\n2. Decrypt\n3. Exit\n");
  9.     printf("Option: ");
  10.     scanf("%d", &choice);
  11.     if (choice == 1)
  12.         choice = encrypt();
  13.     if (choice == 2)
  14.         choice = decrypt();
  15.     if (choice == 3)
  16.         return 0;
  17.     }
  18.     return 0;
  19. }
  20. int encrypt(){
  21.     char buffer[BUFSIZ];
  22.     printf("\n\nInput: ");
  23.     int i=0;
  24.     char c;
  25.     fflush(stdin);
  26.     while((c=getchar()) !='\n'){
  27.         buffer[i++] = c+13;
  28.     }
  29.     buffer[i] = '\0';
  30.     FILE * Output;
  31.     Output = fopen("encrypt.txt", "w+");
  32.     fprintf(Output, buffer);
  33.     fclose(Output);
  34.     return 0;
  35. }
  36. int decrypt(){
  37.     char buffer[BUFSIZ];
  38.     int i=0;
  39.     char c;
  40.     FILE * Input;
  41.     Input = fopen("encrypt.txt", "r");
  42.     while((c=fgetc(Input))!=EOF){
  43.         buffer[i++]= c - 13;
  44.     }
  45.     buffer[i] = '\0';
  46.     printf("\n%s\n", buffer);
  47.     fclose(Input);
  48.     return 0;
  49. }