Advertisement
Guest User

Untitled

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