I have the following relevant code for encrypting in the Vigenere cipher: (Note: I created a function called shift that shifts a character by a certain amount.) int main (int argc, string argv[]) {
if (argc != 2) {
printf("over\n");
return 1;
}
else {
string plain_text = GetString();
string key = argv[1];
string new_text = malloc(strlen(plain_text));
int keylength = strlen(key);
int lenfroma[keylength];
for (int x = 0; x < strlen(key); x++) {
int keyx = (int)tolower(key[x]);
int keya = 97;
lenfroma[x] = keyx-keya;
// printf("len from a first is %i\n", lenfroma[x]);
}
int num_of_space = 0;
for (int m = 0; m < strlen(plain_text); m++) {
if (m < strlen(key)) {
new_text[m] = shift(plain_text[m],lenfroma[m]);
// printf("doing 1, new text m is %c\n", new_text[m]);
if (new_text[m] == ' ') {
num_of_space += 1;
}
}
else {
int a = strlen(key);
int realm = m - num_of_space;
int x = (realm%a);
new_text[m] = shift(plain_text[m],lenfroma[x]);
// printf("len from a is %i\n", lenfroma[x]);
// printf("doing 2, new text m is %c\n", new_text[m]);
if (new_text[m] == ' ') {
num_of_space += 1;
}
}
}
for (int m = 0; m < strlen(new_text); m++) {
printf("%c",new_text[m]);
}
printf("\n");
} } When I run "check50 2015.fall.pset2.vigenere vigenere.c", the output is at: https://sandbox.cs50.net/checks/a26e544f5f354bbe9b9f585a14b8effc
The main error that I am confused by is :( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword \ expected output, but not "xoqmd, tax iekmo!\n"
All of the other outputs are returned accurately. Is there anything wrong with my logic? Thanks in advance.