0

I get these 3 errors when checking viginere with check50

:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
   \ expected output, but not "xomqd, szz gflkp!\n"

:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
   \ expected output, but not "CaQGoh\n"

:( rejects "Hax0r2" as keyword
   \ expected output, but not a prompt for input

How to fix these errors please?

1
  • Your question is not well detailed, i think you need to explain it better!
    – user007
    Jun 21 '14 at 8:30
1
:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
   \ expected output, but not "xomqd, szz gflkp!\n"

:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
   \ expected output, but not "CaQGoh\n"

To fix these 2 errors, you need to fix the algorithm for ciphering. Please watch this short on vigenere and make sure you understand it well!

Here's my algorithm for how vigenere works

Calculate the length of the keyword

Assign each char in the keyword a value in [0 - 25]
Store these keys in an int array named keys

declare an int variable named index to hold the index of the current key

for each character in the plaintext
{
    declare a char variable named curr to hold the current char in the plaintext

    if curr is an alphabetical char
    {
        if curr is an uppercase char
        {
            cipher it as an uppercase char using keys[index]
        }
        else
        {
            cipher it as a lowercase char using keys[index]
        }
        increment index (considering wrapping around the elements of keys)
    }
    print curr out
}

The tricky part of this algorithm is wrapping around the elements of keys. You may take a look at this answer to get some sort of an idea about how you can do that!

:( rejects "Hax0r2" as keyword
   \ expected output, but not a prompt for input

To fix this last error, you need to iterate over the characters of keyword at the beginning of your program. And if one of this characters is NOT an alphabetical char, you may print an error message and return 1 immediately!

You may have a look at the isalpha() function by opening up the terminal and executing

man isalpha

or visiting this link!

0

I can't see the part I need, are you upgrading j just after a change or at any step of the i loop?, think that if the character is not alphabetical you don't code it, and also, the key won't apply until the character is alphabetical

String: W o r l d ,   s a y   h e l l o !
Key:    b a z b a - - z b a - z b a z b -
0

What your doing here is simply adding the enciphering value to the letter and printing it, without worrying whether or not it is even a letter. To ensure that the enciphered text also contains valid letter characters, make a check in your code, and see whether or not the cipher[i] has an ASCII value of less than 'Z' if in the normal plaintext it was capital or if in the normal plaintext, it's non capital, check to make sure it's ASCII value is less than 'z'. Now that you know that, you'll have to subtract the ASCII value of the current variable from 'z' or 'Z' accordingly. This value would be added to 'A' or 'a' to receive the correct ciphered text that can be printed correctly.

Now that you know what you're supposed to do, I think you can implement it yourself, in case you're having problems with that, drop questions here.

Happy Coding!

1
  • j is updated in each change, as well as i, I think I control best 'kj' rather than 'si', and '\0' control. increasing i, j. when j, reaches its final starts at zero, but if the plaintext is higher starts j but i continued Jun 21 '14 at 18:13

This site is temporarily in read only mode and not accepting new answers.

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