Advertisement
Guest User

Untitled

a guest
Oct 14th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 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.  
  25.  
  26.  
  27.  
  28.  
  29.     // setting the cipher to the correct amount
  30.         for (int a = 0; a <= (strlen(b)); a++)
  31.         for (int i = 0; i < strlen(s); i++)
  32.             {
  33.             {
  34.                  if (a == strlen(b))
  35.             {
  36.                 a = 0;
  37.             }
  38.                 if (islower(b[a]))
  39.                 {
  40.                     b[a] = toupper(b[a]);
  41.                 }
  42.                 if (isupper(b[a]))
  43.                 {
  44.                     b[a] = b[a] - 65;
  45.  
  46.                 }
  47.                 {
  48.  
  49.  
  50.  
  51.  
  52.                      {
  53.         // making sure the code wraps around capital z instead of going over it
  54.                         while (s[i] + b[a] > (int)'Z' && isupper(s[i]))
  55.  
  56.                         {
  57.  
  58.                             s[i] = s[i] - 26;
  59.                         }
  60.  
  61.                             if (ispunct(s[i]) || isspace(s[i]))
  62.                                 {
  63.                                     s[i] = s[i] - b[a];
  64.                                 }
  65.                      }
  66.  
  67.  
  68.          // making sure the code wraps around lowercase z instead of going over it
  69.                     {
  70.                          while (s[i] + b[a] > (int)'z' && islower(s[i]))
  71.  
  72.                         {
  73.  
  74.                             s[i] = s[i] - 26;
  75.                         }
  76.                     }
  77.                     if (i ==strlen(s) - 1)
  78.                     {
  79.                         break;
  80.                     }
  81.             }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.                 {
  90.  
  91.                  {
  92.  
  93.  
  94.                  printf("%c", s[i] + b[a]);
  95.  
  96.                     }
  97.  
  98.  
  99.             }
  100.  
  101.  
  102.         }
  103.     }
  104. }
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement