Advertisement
Ayakali

Untitled

Feb 26th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. int a;
  7. string plaintext;
  8. int i;
  9.  
  10. int main(int argc, string argv[])
  11. {
  12. a = strlen(argv[1]);
  13.  
  14. if (a != 26 && !isalpha(argv[1]))
  15. {
  16. printf("Enter a key with 26 alphabetic characters.\n");
  17. return 1;
  18. }
  19. else
  20. {
  21. plaintext = get_string("plaintext: ");
  22. printf("ciphertext: ");
  23.  
  24. for (i = 0; i < strlen(plaintext); i++)
  25. {
  26. if (isalpha(plaintext[i]))
  27. {
  28. if (islower(plaintext[i]))
  29. {
  30. printf("%c", tolower(argv[1][i]));
  31. }
  32. else if (isupper(plaintext[i]))
  33. {
  34. printf("%c", toupper(argv[1][i]));
  35. }
  36. else
  37. {
  38. printf("%c", argv[1][i]);
  39. }
  40. }
  41. else
  42. {
  43. printf("%c", (char)plaintext[i]);
  44. }
  45. }
  46.  
  47. }
  48.  
  49. printf("\n");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement