Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. int main(int argc, string argv[])
  6. {
  7.  
  8. if(argc == 2)
  9. {
  10. for(int i = 0; i < strlen(argv[1]); i++)
  11. {
  12. if(!isdigit(argv[1][i]))
  13. {
  14. printf("Usage: ./caesar key");
  15. return 0 ;
  16. }
  17. }
  18. string pi = get_string("paintext: ");
  19. int size = strlen(pi);
  20. int k = atoi(argv[1]);
  21. char ci[size+1];
  22. ci[size] = '\0';
  23. for(int j = 0; j < size; j++)
  24. {
  25. ci[j] = (pi[j] + k) % 26;
  26. }
  27. printf("cliphertext: %s\n", ci);
  28.  
  29.  
  30. }
  31. else
  32. {
  33. printf("Usage: ./caesar key");
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement