0
        int j = 0;//Declare variable for indexing the 'key'
        int k = strlen(key);//Declare variable and store the length of 'key'
        code = toupper(key[j] % k) - 65;//Convert key to uppercase and store as int
        text = GetString();//Get text from user for encoding

        for (int i = 0, n = strlen(text); i < n; i++)//Loop through each char in 'text'
        {
            if (isalpha (text[i]))//Checks if char is a letter
            {
                if (isupper (text[i]))//Checks if letter is uppercase
                {
                    int x = (((text[i] - 65) + code) % 26 + 65);//Applies cypher to letter and stores as int
                    printf("%c", x);//Prints the encoded letter to screen
                }
                if (islower (text[i]))//Checks if letter is lowercase
                {
                    int y = (((text[i] - 97) + code) % 26 + 97);//Applies cypher to letter and stores as int
                    printf("%c", y);//Prints the encoded letter to screen
                }
                j++;//Increments the key
            }


:) vigenere.c exists
:) vigenere.c compiles
:( encrypts "a" as "a" using "a" as keyword
   \ expected output, but not "T\n"
:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
   \ expected output, but not "RJMaY, NVT ]ZaaJ!\n"
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
   \ expected output, but not "5T+9HH\n"
:( encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
   \ expected output, but not "54+9((\n"
:) handles lack of argv[1]
:) handles argc > 2
:) rejects "Hax0r2" as keyword

When I run my code, it encrypts the entire message using only the first letter of my command line argument. Obviously it is not incrementing correctly. I have spent 8+ hours revising the above snippet of code to try and get it to increment correctly. I'm just not seeing it and need to be pointed in the right direction.

0

Whoo Hoo! Finally figured it out! Such a small change had big results!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .