I have finished the first case : both plaintext and key are isupper.(The Link) However, I got some problems when doing either one of them is islower. Can anyone give me some hints of the formula?


Maybe it gets clearer if you use 'A' instead of 65 (char is a kind of integer, so 'A' is an 8-bit integer of value 65).

In case of a lowercase letter, subtract 'a' (or 97) instead of 'A' (or 65). And in the last step add the one that matches the case of the plaintext letter, not the key letter.

You could reduce your cases from four combinations to two by ignoring the keyword case, like toupper(k[l]) - 'A'.

  • But can i still keeping to use '65' and '97' instead of 'a' and 'A'? Because I also use this method when doing caesar.c and I want to keep it to be consistent. Besides, when I double check, the calculation is incorrect. However, I donnt know which step i did it wrong. Would you mind to help me to check? It has been more than 3 days and I still cannot solve it...pastebin.com/44GqXniv – Christy Ng Jan 28 '18 at 7:27
  • Sure you can use 65 and 97. Your code is lacking lines for the other three combinations (as I said, you could reduce those). Much worse, the structure is all messed up, not related to upper-/lower-case at all. Do not use nested loops. In a first loop, abort on any non-letter. Then, in a second loop, loop over plaintext. The index for the key like the one for the text starts with 0 and has to be incremented manually after encrypting a letter, but not after copying a non-letter. – Blauelf Jan 28 '18 at 9:12

You must log in to answer this question.

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