Repository commit
c0db072 (master)
Python version (python --version)
Python 3.12.13
Dependencies version (pip freeze)
Standard library only.
Expected behavior
The A1Z26 cipher maps the letters a–z to the integers 1–26. Any character outside that alphabet is not defined by the cipher and — per the project's contribution guide ("raise Python exceptions (`ValueError`, etc.) on erroneous input values") — should raise ValueError rather than silently return meaningless output.
Actual behavior
ciphers.a1z26.encode performs no input validation and just runs ord(ch) - 96 for every character. As a result it silently produces nonsense output for perfectly plausible inputs such as uppercase strings or strings containing punctuation/whitespace:
>>> from ciphers.a1z26 import encode
>>> encode("A")
[-31]
>>> encode("HELLO")
[-24, -27, -20, -20, -17]
>>> encode("hi there")
[8, 9, -64, 20, 8, 5, 18, 5]
The main() block at the bottom of the file already normalises with .strip().lower(), showing the author is aware only lowercase input is meaningful — but programmatic callers get no such protection, and there is no test coverage for these edge cases.
This is a minor bug (works correctly for the doctested lowercase input), but the silent wrong output is worse than an explicit error, and violates the guideline above.
Suggested fix
Reject any character outside a–z (and reject the empty string, which is also not meaningful) with a clear ValueError, and add doctests covering the new behaviour. A PR is being opened.
Repository commit
c0db072 (master)
Python version (python --version)
Python 3.12.13
Dependencies version (pip freeze)
Standard library only.
Expected behavior
The A1Z26 cipher maps the letters
a–zto the integers1–26. Any character outside that alphabet is not defined by the cipher and — per the project's contribution guide ("raise Python exceptions (`ValueError`, etc.) on erroneous input values") — should raiseValueErrorrather than silently return meaningless output.Actual behavior
ciphers.a1z26.encodeperforms no input validation and just runsord(ch) - 96for every character. As a result it silently produces nonsense output for perfectly plausible inputs such as uppercase strings or strings containing punctuation/whitespace:The
main()block at the bottom of the file already normalises with.strip().lower(), showing the author is aware only lowercase input is meaningful — but programmatic callers get no such protection, and there is no test coverage for these edge cases.This is a minor bug (works correctly for the doctested lowercase input), but the silent wrong output is worse than an explicit error, and violates the guideline above.
Suggested fix
Reject any character outside
a–z(and reject the empty string, which is also not meaningful) with a clearValueError, and add doctests covering the new behaviour. A PR is being opened.