I was trying to make the vigenere cipher in c for pset2 and i tried to make it according to the instructions in the description for the problem and also in the walkthrough but when i try to make it, the compiler gives me around 20 errors and I don't know what to do. Like in the beginning I have declared all the variables but for some reason the compiler says that the variables I have used in my code are undeclared. And this whole thing has me confused. Please help me out. Also if there is anything that I could do to improve the method that I am currently using to encipher the input given by the user then please let me know.
Thank you, Shayan
Here is my code below:
#include <string.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
int main (int argc, string argv[])
{
string plaintext = GetString();
string plaintext_length = strlen(plaintext);
string key = argv[1];
int key_length = strlen(key);
int shift[key_length];
if (argc != 2) {
printf("The command is not valid and cannot be used as a key to encrypt your message\n");
return 1;
}
for (int i = 0; i < key_length; i++)
{
if (!isaplha(key[i]))
{
printf("The command is not valid and cannot be used as a key to encrypt your message\n");
return 1;
}
}
for (int i = 0; i < key_length; i++)
{
if (isupper(k[i])) {
shift[i] = key[i] - 65;
} else {
shift[i] = key[i] - 97;
}
}
for (int j = 0, i = 0; j < plaintext_length; j++)
{
if (islower(plaintext[j]))
{
plaintext[j] % 122;
printf("%c", (plaintext[j] + shif[i]) % 26);
} else if (isupper(plaintext[j]))
{
plaintext[j] % 90;
printf("%c", (plaintext[j] + shif[i]) % 26);
}
}
}
printf("\n");
return 0;
}