#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
//check if it is valid
if(argc != 2)
{
printf("Error,invalid entry.\n");
return 1;
}
string length = argv[1];
int klength = strlen(length);
int shifted[klength];
int i;
for(i = 0; i < klength; i++)
{
while(!isalpha(argv[1][i]))
{
printf("Error,invalid entry.\n");
return 1;
}
//shift ascii to 0-25
if(isupper(argv[1][i]))
{
shifted[i] = argv[1][i] - 65;
}
else if(islower(argv[1][i]))
{
shifted[i] = argv[1][i] - 97;
}
else if(!isalpha(argv[1][i]))
{
;
}
}
//get plaintext
string plaintext = GetString();
int ptlength = strlen(plaintext);
//encryption
char temp;
int wrap = 0;
for(i = 0; i < ptlength; i++)
{
temp = plaintext[i];
if(isalpha(temp))
{
if(isupper(temp))
{
temp = temp + shifted[wrap%klength];
if(temp > 90)
{
temp = (temp % 90) + 64;
}
printf("%c",temp);
wrap++;
}
else if(islower(temp))
{
temp = temp + shifted[wrap%klength];
if(temp > 122)
{
temp = (temp % 122) + 96;
}
printf("%c", temp);
wrap++;
}
}
else if(temp == ' ')
{
printf(" ");
}
else if(temp != ' ' && !isalpha(temp))
{
printf("%c",temp);
}
else
{
printf("%c",temp);
}
}
printf("\n");
}
[code snipped per Honor Code. In the future, please describe using pseudocode.]