My Vigenere program is working pretty well. It's extremely similar to my code for Caesar, however it's printing the wrong text. Here's my code.
int main(int argc, char *argv[])
{
if(argc < 2)
{
printf("waoh mahn!\n");
return(1);
}
else if(argc > 2)
{
printf("waoh mahn!\n");
return(1);
}
string key = argv[1];
int c = 0;
string input = GetString();
for(int i = 0; i < strlen(input); i++)
{
if(isalpha(input[i]))
{
for(c = 0; c < strlen(key); c++)
{
if(input[i] == 'z')
input[i] = 'a';
else if(input[i] == 'Z')
input[i] = 'A';
else input[i]++;
}
}
}
printf("%s\n", input);
}
Here's the check50, for an example of what it prints.
:) vigenere.c exists
:) vigenere.c compiles
:( encrypts "a" as "a" using "a" as keyword
\ expected output, but not "b\n"
:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
\ expected output, but not "zruog, vdb khoor!\n"
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
\ expected output, but not "EdUIrr\n"
:( encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
\ expected output, but not "EDUIRR\n"
:) handles lack of argv[1]
:) handles argc > 2
:( rejects "Hax0r2" as keyword
\ expected output, not a prompt for input
I can't really seem to tell what the issue is here yet. I also haven't programmed it to reject Hax0r2 yet, but that won't be much of an issue.