I've been banging my head trying to figure out why my ciphertext ends up ciphering by a completely different number, and including non-alpha characters.

My cipher code is as follows, with ASAL being 71 and ASAU being 65 ~/workspace/pset2_test/caesar/ $ ./caesar7 15 plaintext: haiLey paTrick ciphertext: ]V^AZT KVIM^X I tried a key of 15 and in the example below, the key is -5, and somehow that translated to a shift of -11 along the ascii table. ~/workspace/pset2_test/caesar/ $ ./caesar 15 plaintext: haiLey paTrick ciphertext: ]V^AZT KVIM^X

If I take the first letter, "h", that should come out as 'w" in the ciphertext. I tried calculating the equation by hand, and I got this:

With the %26, I get ((104-71)+15)%26+71=112.
Without %26, I get ((104-71)+15)+71=119, the ascii code for lowercase w.

Obviously, something is wrong here, but I have no idea what it could be. Any help would be greatly appreciated.


Why 71? 'a' is an 8-bit integer with decimal representation of 97.


For upper-case letters, it would be 'A' or 65. Since in C, characters are integers, you could even use letters in the formula, like (input_letter-'A'+key)%26+'A'.

  • Thanks for saving me again, Blauelf! I heard Zamyla talking about an alphabetical index in the walkthrough, and figured it would be one index that contianed both uppercase and lowercase letters, staring with uppercase A and ending with lowercase z, where lowercase a would be at position 26 in the index.
    – contranull
    Nov 23 '17 at 19:23

You must log in to answer this question.

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