Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.33 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. //i is what number character of the string, s asks you for a string, n asks you what the key is, and b is what will be printed
  7. // lines 8 to 14 makes sure the user puts in 2 command line arguments
  8. // int a is what number character of the cipherc code
  9.  
  10. int main(int argc, string argv[])
  11. {
  12.     //making sure I have two command line arguments
  13.     if (argc != 2)
  14.  
  15.     {
  16.         printf("Usage:%s abc\n" , argv[0]);
  17.         return 1;
  18.     }
  19.     //code only runs with two command line arguments
  20.     if (argc == 2)
  21.     {
  22.         string s = get_string("plaintext: ");
  23.         string b = (argv[1]);//argv1 is the string given at the command line argument
  24.         int a = 0;
  25.  
  26.  
  27.  
  28.  
  29.         // setting the cipher to the correct amount
  30.  
  31.             for (int i = 0; i <= strlen(s); i++)
  32.  
  33.  
  34.             {
  35.                 if (i >= strlen(b))
  36.                 {
  37.                     a = i - strlen(b);
  38.                 }
  39.                 else
  40.                 {
  41.                     a = i;
  42.                 }
  43.  
  44.                 {
  45.  
  46.  
  47.                     if (islower(b[a]))
  48.                     {
  49.                         b[a] = toupper(b[a]);
  50.                     }
  51.                     if (isupper(b[a]))
  52.                     {
  53.                         b[a] = b[a] - 65;
  54.  
  55.                     }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.                             // making sure the code wraps around capital z instead of going over it
  63.                             while (s[i] + b[a] > (int)'Z' && isupper(s[i]))
  64.  
  65.                             {
  66.  
  67.                                  s[i] = s[i] - 26;
  68.                             }
  69.  
  70.                                 if (ispunct(s[i]) || isspace(s[i]))
  71.                                 {
  72.                                     s[i] = s[i] - b[a];
  73.                                 }
  74.  
  75.  
  76.  
  77.                                 // making sure the code wraps around lowercase z instead of going over it
  78.  
  79.                                     while (s[i] + b[a] > (int)'z' && islower(s[i]))
  80.  
  81.                                     {
  82.  
  83.                                         s[i] = s[i] - 26;
  84.                                     }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.                                 printf("%c", s[i] + b[a]);
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.                 }
  111.         }
  112.  
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement