[Python / Rotational Cipher] Inaccuracy in exercise instructions (key count)

Hi there,

While working on Rotational Cipher, I noticed an error in the exercise description:

“It is stronger than the Atbash cipher because it has 27 possible keys, and 25 usable keys.”

The total number of possible keys should be 26, not 27, to match the 26 letters in the Latin alphabet (shifts 0 through 25, where a shift of 0 leaves the text unchanged and keys 1 to 25 produce meaningful shifts).

Suggested correction:

“It is stronger than the Atbash cipher because it has 26 possible keys, and 25 usable keys.”

I would be happy to open a pull request to update this if you’d like.

Please have a look at https://exercism.org/docs/community/being-a-good-community-member/suggesting-exercise-improvements#h-practice-exercises. This isn’t Python-specific docs.

The instructions say,

The Caesar cipher is a simple shift cipher that relies on transposing all the letters in the alphabet using an integer key between 0 and 26.

That’s 27 keys that I can count :slight_smile:

Thanks for the clarification and for retagging this! :slightly_smiling_face:

The line you quoted actually points right to the root of the issue:

“The Caesar cipher is a simple shift cipher that relies on transposing all the letters in the alphabet using an integer key between 0 and 26.”

Because a Caesar cipher operates modulo 26, a shift of 0 and a shift of 26 are functionally identical—both produce the exact same identity transformation (no change to the text).

Specifying 0 to 26 counts that identical shift twice. That is also why the instructions deduce there are only 25 usable keys (27 - 2 = 25, throwing away both 0 and 26).

For a 26-letter alphabet, the set of distinct keys is:

  • 0 through 25 (or 1 through 26) \rightarrow 26 possible keys
  • Excluding the single identity shift leaves 25 usable keys

Updating that sentence to define the key as an integer “between 0 and 25” would resolve the double-counting and correct the total key count to 26. Let me know what you think!

0 and 26 are both valid keys. They have the same effect and both are not useful (or, usable), but they are distinct values and distinct keys.

Are you suggesting that only one of those two keys is a valid key? Is there a reason one key is more valid than the other?

Neither key is more valid than the other—they represent the exact same key.

In cryptography, keyspace refers to the number of distinct transformations (permutations) a cipher can produce. Because a shift cipher operates on a 26-letter cycle:

  • If 0 and 26 are counted as distinct keys simply because they are distinct integer values, then 52, 78, or -26 would also be distinct keys, making the total number of keys infinite.

  • Just like on a 12-hour clock where moving forward 12 hours brings you right back to where you started, key k and key k + 26 perform the exact same mapping.

To represent every distinct key without duplication, the keyspace is conventionally defined using a single full cycle—either 0 through 25 or 1 through 26. Defining it as 0 through 26 counts the identity transformation twice, which is how the document arrives at 27 total keys instead of 26.

I can see where OP is coming from that the two keys are functionally equivalent, but it’s unclear that the proposed change adds clarity that were missing. The important thing for students is that the integer key will be 0 to 26. Whether it’s 26 or 27 possible keys is a distinction that I don’t think we need to resolve in the instructions.