:( 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!