I've checked my work, and I am failing the "Hax0r2" keyword test, but I cannot figure out why. My code is supposed to reject any argv[1] that is not all alphabetic characters. Will someone take a look and let me know what I am doing wrong?
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./vigenere k\n");
return 1;
}
string key = argv[1];
int keylength = strlen(key);
for (int i = 0; i < keylength; i++)
{
if (!isalpha(key[i]))
{
printf("Usage: ./vigenere k\n");
return 1;
}
string plaintext = get_string("plaintext: ");
int ptlength = strlen(plaintext);
printf("ciphertext: ");
for (int j = 0, k = 0; j < ptlength; j++)
{
char keyconversion = tolower(key[k % keylength]) - 97;
char uppercipher = (((plaintext[j] + keyconversion - 65) % 26) + 65);
char lowercipher = (((plaintext[j] + keyconversion - 97) % 26) + 97);
if isupper(plaintext[j])
{
printf("%c", uppercipher);
k++;
}
else if islower(plaintext[j])
{
printf("%c", lowercipher);
k++;
}
else
{
printf("%c", plaintext[j]);
}
}
printf("\n");
return 0;
}
}
}
, right? Is that the version you are submitting (after having saved), or are you accidentally submitting a different file?