The title says it all, I can't get my key to repeat itself correctly after one repetition. For example, if my key is 3 letters and GetString is 6, then the last3 letters of GetString will be incorrectly translated. Here's my code:
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Enter your key after ./vigenere\n");
return 1;
}
string key = argv[1];
printf("Enter plaintext: ");
string p = GetString();
int i;
for (i = 0; i < strlen(p); i++)
{
if (isspace(p[i]))
{
printf(" ");
}
if (ispunct(p[i]))
{
printf("%c", p[i]);
}
if (isalpha(p[i]))
{
int code = (p[i] + key[i]) % 26;
if (isupper(p[i]))
{
if (code == 18)
{
printf("%c", code + 47);
}
if (code > 18)
{
if ((code + 39) < 91)
{
printf("%c", code + 65);
}
if ((code + 39) >= 91)
{
printf("%c",((code + 39) % 91) + 65);
}
}
if (code < 18)
{
if ((code + 65) < 91)
{
printf("%c", code + 65);
}
if ((code + 65) >= 91)
{
printf("%c", ((code + 65) % 91) + 65);
}
}
}
}