0

So I had the cipher working properly when using an all lowercase key, but now that I'm trying to check uppercase key characters, my cipher no longer works.

For a key of "bacon" and a phrase of "meet me," it just returns "bbbbbbb." This leads me to believe that it's getting hung up somewhere in the loop and j is not incrementing as I want it to.

2
  • How are you setting keylength? And are you doing anything to the key string before the posted code?
    – Cliff B
    Feb 3, 2016 at 22:45
  • Hi Cliff: I've attached the preceding section of code for the sake of clarity. Thanks!
    – klmo8
    Feb 3, 2016 at 22:57

1 Answer 1

1

I'm not sure, but I think it's a problem with misplaced parentheses. Look at the following line:

if (islower(key[j] && (islower(encrypt[i]))))

Now, look at a slightly modified version of it where I have replaced a matched pair of parentheses with curly braces simply for clarity:

if (islower {  key[j] && (islower(encrypt[i])) } )

I'm not sure how that's going to behave, but islower() is trying to process the logical and of key[j] and a true/false result of the second islower() call. I would think it needs to be:

if (islower(key[j]) && islower(encrypt[i]) )

If this answers your question, please click on the check mark to accept. Let's keep up with forum maintenance. ;-)

0

You must log in to answer this question.

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