Current code:
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char buf[BUFSIZ];
char temp[100];
int i = 0, choice = 0;
printf("\nThis program allows you to encrypt/decrypt");
printf(" lines of text under %d characters. \n", sizeof(buf) );
printf("---------------------------------------------------");
printf("-----------------------------");
printf("Please enter a number: 1-Encrypt, 2-Decrypt,");
printf(" 3-Exit: ");
fgets( temp, sizeof temp, stdin );
sscanf( temp, "%d", &choice );
while ( choice != 0 )
{
if (choice == 1)
{
printf("\nPlease enter the text you wish to encrypt: ");
fgets(buf, sizeof(buf), stdin);
{
while ( buf[i] != '\0' )
{
buf[i] = buf[i] + 3;
i++;
}
}
printf("\n Your encrypted text is: %s \n", buf);
printf("\nWould you like to encrypt/decrypt something else?\n");
printf("1-Encrypt, 2-Decrypt, 3-Exit: ");
fgets( temp, sizeof temp, stdin );
sscanf( temp, "%d", &choice );
fflush(stdin);
} // End of choice 1 'if' statement
if ( choice == 2 )
{
printf("\nPlease enter the text you wish to decrypt: ");
fgets(buf, sizeof(buf), stdin);
{
while ( buf[i] != '\0' )
{
buf[i] = buf[i] - 3;
i++;
}
}
printf("\nYour decrypted text is: %s \n", buf);
printf("\nWould you like to encrypt/decrypt something else?\n");
printf("1-Encrypt, 2-Decrypt, 3-Exit: ");
fgets( temp, sizeof temp, stdin );
sscanf( temp, "%d", &choice );
fflush(stdin);
} // End of choice 2 'if' statement
if ( choice == 3)
{
printf("\nThank you for using my encryption program! Have a nice day!\n");
return 0;
}
else
{
printf("\nThat is not a valid option!! 1-Encrypt, 2-Decrypt,");
printf(" 3-Exit: ");
fgets( temp, sizeof temp, stdin );
sscanf( temp, "%d", &choice );
fflush(stdin);
}
} // End of while loop
} // End of main statement