Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MODE_ENCRYPT 1
- #define BUF_SIZE 1024
- void InputError();
- void Encrypt(char *text, int key);
- int main(int argc, char *argv[])
- {
- int i, n, mode, key;
- char input[BUF_SIZE];
- // make sure the argument count was as expected, if not, print error
- if(argc != 3)
- {
- InputError(); // if you pass a code of a string here, you can add a custom error message for each failure case
- return EXIT_FAILURE;
- }
- else
- {
- // now check the work command
- if(strcmp(argv[1], "-e")) // alternative: check for argv[1][0] == '-', argv[1][1] == 'e', ...
- {
- mode = MODE_ENCRYPT; // detected encryption mode
- }
- // and now verify that the cipher is a number and then convert it(atoi, sscanf, ...)
- for(i = 0, n = strlen(...); i < n; i++)
- {
- // check each character if it is a number
- }
- }
- printf("Enter text to %s\n", mode == MODE_ENCRYPT ? "encrypt" : "decrypt");
- fgets(input, BUF_SIZE, stdin);
- switch (mode)
- {
- case MODE_ENCRYPT:
- Encrypt(input, key);
- break;
- }
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment