I am not getting the desired output when I want cipher the plaintext with key 13 with long sentence with commas and space. Please help, thank you.
//Program to encrypt the message by using Caesar's cipher
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main(int argc, string argv[])
{
//make sure the program was run with command-line argument
if (argc == 2)
{
//validate the key
int key = atoi(argv[1]);
int len = strlen(argv[1]);
// iterate over the key
for (int i = 0; i < len; i++)
{
if (!isdigit(argv[1][i]))
{
printf("Usage: ./caesar key\n");
return 1;
}
else if (isalpha(argv[1][i]))
{
printf("Usage: ./caesar key");
return 1;
}
}
// prompt user for plaintext
string plaintext = get_string("plaintext: ");
printf("ciphertext: ");
// iterate over the plaintext
int length = strlen(plaintext);
for (int i = 0; i < length; i++)
{
if (islower(plaintext[i]))
{
printf("%c",plaintext[i] + 'a' + key % 26 - 'a');
}
else if (isupper(plaintext[i]))
{
printf("%c", plaintext[i] +'A' + key % 26 - 'A');
}
else
{
printf("%c", plaintext[i]);
}
}
printf("\n");
}
else
{
printf("Usage: ./caeasr key\n");
return 1;
}
return 0;
}