Advertisement
Guest User

caesar

a guest
Oct 21st, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. int main(int argc, string argv[]){
  8. int n=0,key=0;
  9. //sanity check for int
  10. printf("*");
  11. printf("\nInput:");
  12. string input=GetString();
  13. printf("%s",input);
  14. if(argc!=2)
  15. {
  16. printf("Invalid\n");
  17. }else
  18.  
  19. key=atoi(argv[1]);
  20. n=strlen(input);
  21. for(int i=0;i<n;i++)
  22. {
  23. if(isupper(input[i]))
  24. {
  25. int convnum=(input[i]-65);
  26. int cipher=(convnum+key)%26;
  27. //convert to normal asci again and print
  28. int asciwrd=cipher+65;
  29. printf("%c",asciwrd);
  30. }
  31. else if(islower(input[i]))
  32. {
  33. int convnum=input[i]-97;
  34. int cipher=(convnum+key)%26;
  35. int asciwrd=cipher+97;
  36. printf("%c",asciwrd);
  37. }
  38. else
  39. printf("%i",input[i]);
  40. printf("\n");
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement