Advertisement
Guest User

Untitled

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