Guest User

Wont Cipher Text

a guest
Dec 29th, 2016
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. int main(int argc, string argv[])
  8. {
  9. string s = GetString();
  10. int k = atoi(argv[1]);
  11.  
  12.  
  13. if(argc != 2)
  14. {
  15. return 1; //ensures the propper amount of arguemnets
  16. }
  17.  
  18. for(int i = 0; i == strlen(s); i++)
  19. {
  20. char c = s[i];
  21. if(isupper(c))//checks for uppercase
  22. {
  23. char caesar = (((c - 65) + k) % 26) + 65; //ciphers the text >> example (((65 - 65) + 1) MOD 26)+ 65 = 66 (B)
  24. printf("%c", caesar);
  25. }else
  26. if(islower(c))//checks for lowercase
  27. {
  28. char lowerCaesar = (((c - 97) + k) % 26) +65;//ciphers the text >> example (((97 - 97) + 1) MOD 26)+ 97 = 98 (b)
  29. printf("%c", lowerCaesar);
  30. }else
  31. {
  32. printf("%c", c); //prints non letters; ! , . - _ %
  33. }
  34.  
  35. }
  36. printf("\n"); // prints the newline
  37. }
RAW Paste Data