|
| 1 | +# Rotational Cipher |
| 2 | + |
| 3 | +Create an implementation of the rotational cipher, also sometimes called the Caesar cipher. |
| 4 | + |
| 5 | +The Caesar cipher is a simple shift cipher that relies on |
| 6 | +transposing all the letters in the alphabet using an integer key |
| 7 | +between `0` and `26`. Using a key of `0` or `26` will always yield |
| 8 | +the same output due to modular arithmetic. The letter is shifted |
| 9 | +for as many values as the value of the key. |
| 10 | + |
| 11 | +The general notation for rotational ciphers is `ROT + <key>`. |
| 12 | +The most commonly used rotational cipher is `ROT13`. |
| 13 | + |
| 14 | +A `ROT13` on the Latin alphabet would be as follows: |
| 15 | + |
| 16 | +```text |
| 17 | +Plain: abcdefghijklmnopqrstuvwxyz |
| 18 | +Cipher: nopqrstuvwxyzabcdefghijklm |
| 19 | +``` |
| 20 | + |
| 21 | +It is stronger than the Atbash cipher because it has 27 possible keys, and 25 usable keys. |
| 22 | + |
| 23 | +Ciphertext is written out in the same formatting as the input including spaces and punctuation. |
| 24 | + |
| 25 | +## Examples |
| 26 | + |
| 27 | +- ROT5 `omg` gives `trl` |
| 28 | +- ROT0 `c` gives `c` |
| 29 | +- ROT26 `Cool` gives `Cool` |
| 30 | +- ROT13 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` |
| 31 | +- ROT13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.` |
| 32 | + |
| 33 | + |
| 34 | +## Exception messages |
| 35 | + |
| 36 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 37 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 38 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 39 | +a message. |
| 40 | + |
| 41 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 42 | +`raise Exception`, you should write: |
| 43 | + |
| 44 | +```python |
| 45 | +raise Exception("Meaningful message indicating the source of the error") |
| 46 | +``` |
| 47 | + |
| 48 | +## Running the tests |
| 49 | + |
| 50 | +To run the tests, run `pytest rotational_cipher_test.py` |
| 51 | + |
| 52 | +Alternatively, you can tell Python to run the pytest module: |
| 53 | +`python -m pytest rotational_cipher_test.py` |
| 54 | + |
| 55 | +### Common `pytest` options |
| 56 | + |
| 57 | +- `-v` : enable verbose output |
| 58 | +- `-x` : stop running tests on first failure |
| 59 | +- `--ff` : run failures from previous test before running other test cases |
| 60 | + |
| 61 | +For other options, see `python -m pytest -h` |
| 62 | + |
| 63 | +## Submitting Exercises |
| 64 | + |
| 65 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/rotational-cipher` directory. |
| 66 | + |
| 67 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 68 | + |
| 69 | +For more detailed information about running tests, code style and linting, |
| 70 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 71 | + |
| 72 | +## Source |
| 73 | + |
| 74 | +Wikipedia [https://en.wikipedia.org/wiki/Caesar_cipher](https://en.wikipedia.org/wiki/Caesar_cipher) |
| 75 | + |
| 76 | +## Submitting Incomplete Solutions |
| 77 | + |
| 78 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments