Repository navigation
R23-T053: Add input validation to ciphers/porta_cipher.py - #63
Open
code-paul-creator wants to merge 1 commit into
Open
code-paul-creator wants to merge 1 commit into
code-paul-creator wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ciphers/porta_cipher.pyhad no input validation: bad keys or text crashed with confusing errors (IndexError, KeyError, AttributeError) and one case (ßas a key) silently gave a wrong result. This PR adds clearTypeError/ValueErrormessages, documents the input contract, and adds a doctest for every new error path.Related Issue
Fixes: #53
Type of Change
Changes Made
validate_letters(name, value, allow_empty=False):TypeErrorfor non-str,ValueErrorfor empty or non-ASCII-letter input, naming the offending character.generate_tablevalidates the key;encryptvalidates the text (decryptinherits both).work/R23-T053/PROBE.md(18 bad inputs, before vs after) andprobe_bad_inputs.py.Screenshots / Recordings
Not applicable (no UI changes).
Testing
python -m pytest --doctest-modules ciphers/porta_cipher.py-> passed (27 doctests)python -m doctest -v ciphers/porta_cipher.py-> 27 passed, 0 failedruff check ciphers/porta_cipher.py-> all checks passedpython work/R23-T053/probe_bad_inputs.py-> every bad input now raises a clear errorChecklist
Additional Notes
Findings (before -> after): empty key IndexError -> ValueError; digit/space/non-ASCII key KeyError -> ValueError; None/int/bytes key AttributeError/KeyError -> TypeError; text with space/digit "substring not found" -> ValueError naming the character;
ßkey silently accepted (upper() gives 'SS') -> ValueError. Full table inwork/R23-T053/PROBE.md.