fork download
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6.  
  7. int main(int argc, string argv[])
  8. {
  9. int alph_indx(char ch);
  10. if (argc != 2)
  11. {
  12. printf("usage ./vigenere keyword, where k is non negative integer");
  13. return 1;
  14. }
  15. string k = argv[1];
  16. printf("plaintext: ");
  17. string plaintext = get_string();
  18. string ciphertext = plaintext;
  19. //encipher
  20. for (int i = 0, n = 0; i < sizeof(plaintext); i++)
  21. {
  22. if (isalpha(plaintext[i]))
  23. {
  24. if (isupper(plaintext[i]))
  25. {
  26. //toupper
  27. ciphertext[i] = ( alph_indx(plaintext[i]) + alph_indx(k[n % strlen(k)]) ) + 'A';
  28. }
  29. else if (islower(plaintext[i]))
  30. {
  31. //tolower
  32. ciphertext[i] = ( alph_indx(plaintext[i]) + alph_indx(k[n % strlen(k)]) ) + 'a';
  33.  
  34. }
  35. else if (isblank(plaintext[i]))
  36. {
  37. ciphertext[i] = plaintext[i];
  38. }
  39. }
  40. }
  41.  
  42. printf("ciphertext: %s", ciphertext);
  43.  
  44. return 0;
  45.  
  46. }
  47. int alph_indx(char ch)
  48. {
  49. int num = ch;
  50.  
  51. return (isupper(ch)) ? ((num - 'A') % 26) : ((num - 'a') % 26);
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:10: fatal error: 'cs50.h' file not found
#include <cs50.h>
         ^
1 error generated.
stdout
Standard output is empty