The instruction given does not provide sufficient information on how the algorithm works.
(1) when ‘aaaaaaaaaaaaaaaaaa’ is provided as key, what algorithm does it go through to encode? What determines the a = 0 setting?
(2) When ‘ddddddddddddddddd’ is provided as key, what would happen differently in encoding?
(3) Why setting the key to ‘dddd’ would result in Caesar Cipher?
For someone without prior knowledge on cryptology, it is impossible to finish this exercise.
The key tells you how much to shift the letters. a = 0 and d = 4. Those values are the shift distance.
The d refers to the prior description of the Caesar Cipher:
If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others.
Does that help you figure out how to complete the exercise?
It helps, but I still have questions:
(1) If a is set to 0, why is d not set to 3, but 4?
(2) What is the difference between the number of letters used in the keys? For example, does using ‘ddddddddddddddddd’ vs. ‘dddd’ as keys produce different results? If yes, how?
Yes, the tests are helpful. More extremely, I can unlock the community solutions to find out the algorithm. But I feel like these are hacky ways to finish an exercise.
The instruction should lay out the exact algorithm the students are expected to follow. For starters, I think if the instruction explains how ‘aaaaaaaaaaaaaaaaaa’, ‘ddddddddddddddddd’ or ‘dddd’ are used in the encoding process, it would be greatly helpful
That’s a very good question I think a = 0 is base 0 offset and d = 4 is a base 4 offset, i.e. an error. Using a as the key shifts the input by 0 chars. Using d as the key shifts a -> d, b -> e.
No. They produce the same results. Offhand, I forget if the key needs to match the length of the input or if the key needs to be repeated to match the input length. Either the key matches the input length or the patterns d, ddd, dddddddd should all be equivalent. The tests should make that apparent.
The Python track on Exercism is explicitly and intentionally test driven. See the Test Driven Development doc. Exercism as a whole is pretty test driven. The tests are explicitly intended to be the source of truth for the exercise requirements. Reading and/or running the tests to understand the exercise is explicitly part of the intended workflow.
No. They produce the same results. Offhand, I forget if the key needs to match the length of the input or if the key needs to be repeated to match the input length. Either the key matches the input length or the patterns d, ddd, dddddddd should all be equivalent. The tests should make that apparent.
Thank you for your help, but as it turns out this is only partially true. The keys do not have to be matched to the length of the input but are recycled to match the length of the input. More importantly, the keys are letter-for-letter mapped to the input to be encoded. The amount of shift for each letter is determined by the letter of the same position in the key. For example, if the input is ‘xxx’, and the key is ‘abc’. The algorithm would shift 0 (a=0) position for the first letter, 1 (b=1) position for the second letter, and 2 (c=2) position for the third letter, resulting in an output of ‘xyz’.
The above key algorithm details are grossly missing from the instructions. And they are very difficult to figure out by reserve-engineering the tests if not impossible. I would still hope the instructions to be more clear on the algorithm. After all, the students here are to practice their programming skills, not to solve the mystery of the instructions (my humble opinion).
These tests instantiate a Cipher() object then test the value of the self.key attribute. Are you defining a self.key in the Ciper.__init__()? Are you setting it to a string value (and not None)?
self.key needs to be not-None by the time __init__() returns. Setting its value at a later time isn’t sufficient. The tests initialize the object and expect it to have a not-None value prior to calling anything else.
I encourage people to always ask for mentoring! At any stage. Sometimes even multiple times!
Hi everyone, I agree with @J-ZW-Wang that the instructions are suboptimally clear. I spent a long time yesterday staring at the tests and unable to figure out how the key is meant to signal the shift(s). Also, the Simple section on the Wikipedia page on Substitution Ciphers suggests a different usage of the key, which only fostered my misunderstanding.
I would suggest to include one additional sentence after
Given the key “aaaaaaaaaaaaaaaaaa”, encoding the string “iamapandabear” would return the original “iamapandabear”.
Given the key “ddddddddddddddddd”, encoding our string “iamapandabear” would return the obscured “ldpdsdqgdehdu”
Namely, something like:
Given the key “abc”, encoding the string “aaaaaaab” would be result in “abcabcab”, so the nth character of the key determines the shift for characters in the string for which i modulo key_length = n, with i denoting the position of the character in the string.
Something in this direction would make the instructions much clearer and avoid unnecessary time spent deciphering them, which could be better spent solving the exercise.