Advertisement
Guest User

Untitled

a guest
Jan 29th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. # include<cs50.h>
  2. # include<stdio.h>
  3. # include<string.h>
  4. # include<ctype.h>
  5. char ciphertext;
  6. char ascii;
  7. char character;
  8. char cliphertext;
  9.  
  10.  
  11.  
  12.  
  13. int main(int argc, string argv[])
  14. {
  15.     if(argc == 2)
  16.     {
  17.         string k = argv[1];
  18.  
  19.         {
  20.             for (int l = 0, m = strlen(k); l < m; l++)
  21.             if (!isalpha(k[l]))
  22.             {
  23.                 printf ("Please enter alpha.\n");
  24.                 return 1;
  25.             }
  26.             else
  27.             {
  28.                 printf("Plaintext: ");
  29.                 string plaintext = get_string();
  30.  
  31.  
  32.                 for (int i = 0, n = strlen(plaintext); i < n; i++)
  33.  
  34.                 {
  35.                     if (isalpha(plaintext[i]))
  36.                     {
  37.                         if(isupper(plaintext[i]) && isupper(k[l]))
  38.                         {
  39.                             printf("%c", (((plaintext[i] - 65) + (k[l] - 65)) % 26) + 65);
  40.                         }
  41.                         else if(isupper(plaintext[i]) && islower(k[l]))
  42.                         {
  43.                             printf("%c", (((plaintext[i] - 65) + (k[l] - 97)) % 26) + 65);
  44.                         }
  45.                         else if(islower(plaintext[i]) && islower(k[l]))
  46.                         {
  47.                             printf("%c", (((plaintext[i] - 97) + (k[l] - 97)) % 26) + 97);
  48.                         }
  49.                         else if(islower(plaintext[i]) && isupper(k[l]))
  50.                         {
  51.                             printf("%c", (((plaintext[i] - 97) + (k[l] - 65)) % 26) + 97);
  52.                         }
  53.                     }
  54.                     else
  55.                     {
  56.                         printf("%c", plaintext[i]);
  57.                     }
  58.                 }
  59.                 printf("\n");
  60.             }
  61.         }
  62.     }
  63.     else
  64.     {
  65.         printf("Error\n");
  66.         return 1;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement