Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6.  
  7. int main(int argc, string argv[])
  8. {
  9. string k = argv[1];
  10. if (argc == 2 && isalpha(k))
  11. {
  12. goto cypher;
  13. }
  14. else
  15. {
  16. printf("Wrong command-line argument! Try again!\n");
  17. return 1;
  18. }
  19. cypher: printf("Please enter massage you want to cypher!\n");
  20. string text = GetString();
  21. for (int i =0, n = strlen(text), m = strlen(k); i < n; i++)
  22. {
  23. if (isalpha(text[i]))
  24. {
  25. if (isupper(text[i]))
  26. {
  27. char letter = ((text[i] + k[i % m]) - 65) % 26;
  28. printf("%c", letter + 65);
  29. }
  30. else
  31. {
  32. char letterlow = ((text[i] + k[i % m]) - 97) % 26;
  33. printf("%c", letterlow + 97);
  34. }
  35. }
  36. else
  37. {
  38. printf("%c", text[i]);
  39. }
  40. }
  41. printf("\n");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement