Refactor to unified caesar() function with encode/decode support

- Replace separate encrypt/decrypt with shared caesar() function
- Add direction constants (DIRECTION_ENCODE, DIRECTION_DECODE) and
  prompts
- Update main.py to support interactive encode/decode loop
- Keep encrypt/decrypt as wrappers for backward compatibility
- Add tests for caesar() with both directions and error handling
- Update tests for main.py with interactive scenario tests
This commit is contained in:
2026-10-04 13:23:47 +08:00
parent d4b3e6ab19
commit 9d8beb3aef
8 changed files with 139 additions and 33 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
Each letter is moved `shift` places through the alphabet:
`new_position = (ALPHABET.index(letter) + shift) % 26`.
The modulo keeps positions in range for shifts past `z`.
Decryption is encryption with `-shift`. Non-letters are left untouched and letter case is preserved.
Decoding shifts by `-shift`; one shared `caesar(text, shift, direction)` function does both. Non-letters are left untouched and letter case is preserved.
API reference: run `doxygen Doxyfile` from the repository root and open
`docs/doxygen/html/index.html`. The step-by-step plan is in [plan.md](plan.md).