Guest User

Untitled

a guest
Nov 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MODE_ENCRYPT 1
  5. #define BUF_SIZE 1024
  6.  
  7. void InputError();
  8. void Encrypt(char *text, int key);
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. int i, n, mode, key;
  13. char input[BUF_SIZE];
  14. // make sure the argument count was as expected, if not, print error
  15. if(argc != 3)
  16. {
  17. InputError(); // if you pass a code of a string here, you can add a custom error message for each failure case
  18. return EXIT_FAILURE;
  19. }
  20. else
  21. {
  22. // now check the work command
  23. if(strcmp(argv[1], "-e")) // alternative: check for argv[1][0] == '-', argv[1][1] == 'e', ...
  24. {
  25. mode = MODE_ENCRYPT; // detected encryption mode
  26. }
  27. // and now verify that the cipher is a number and then convert it(atoi, sscanf, ...)
  28. for(i = 0, n = strlen(...); i < n; i++)
  29. {
  30. // check each character if it is a number
  31. }
  32. }
  33. printf("Enter text to %s\n", mode == MODE_ENCRYPT ? "encrypt" : "decrypt");
  34. fgets(input, BUF_SIZE, stdin);
  35. switch (mode)
  36. {
  37. case MODE_ENCRYPT:
  38. Encrypt(input, key);
  39. break;
  40. }
  41. return EXIT_SUCCESS;
  42. }
Add Comment
Please, Sign In to add comment