int main (int argc,string argv[]) { string key=argv[1];//get the user key
if (argc!=2) //check the user input
{
printf("Command line argument is not valid\n");
return 1;
}
if (!isalpha(argv[1]))
{ printf("Invalid characters\n"); return 1; }
printf ("plaintext: ");
string p=get_string(); //get the plaintext
printf ("ciphertext: ");
for(int i=0, n=strlen(key);i<n;i++)
{
if (isalpha(key[i]))
{
if (isupper(key[i]))
{
key[i]=key[i]-65;
}
if (islower(key[i]))
{
key[i]=key[i]-97;
}
}
printf ("%c",i) ;
for(int j=0,k=strlen(p);j<k;j++)
{
if (isupper(p[j]))
{
p[j]=((p[j]-65)+key[i])%26 + 65;
}
if (islower(p[j]))
{
p[j]=((p[j]-97)+key[i])%26 + 97;
}
printf("%c",j) ;
}
}
// printf("ciphertext: "); //else //{ // printf("%c",p[i]); //}
printf("\n");
}
{}
button. It adds/removes four spaces in front of every line, and four spaces in front of a line indicate a code block in Stackexchange-flavoured markdown.