Title: R23-T053: Add input validation to ciphers/porta_cipher.py by code-paul-creator · Pull Request #63 · S-AI-Projects/TheAlgorithms-Python · GitHub
Open Graph Title: R23-T053: Add input validation to ciphers/porta_cipher.py by code-paul-creator · Pull Request #63 · S-AI-Projects/TheAlgorithms-Python
X Title: R23-T053: Add input validation to ciphers/porta_cipher.py by code-paul-creator · Pull Request #63 · S-AI-Projects/TheAlgorithms-Python
Description: Description ciphers/porta_cipher.py had 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 clear TypeError/ValueError messages, documents the input contract, and adds a doctest for every new error path. Related Issue Fixes: #53 Type of Change Bug Fix New Feature UI/UX Improvement Performance Improvement Tests Documentation Refactoring / Maintenance CI/CD Changes Made Added validate_letters(name, value, allow_empty=False): TypeError for non-str, ValueError for empty or non-ASCII-letter input, naming the offending character. generate_table validates the key; encrypt validates the text (decrypt inherits both). Documented the input contract in the docstrings (non-empty ASCII-letter key, ASCII-letter text, case-insensitive, empty text returns ''). Added doctests for every new error path (original 5 doctests unchanged; 27 doctests total). Added work/R23-T053/PROBE.md (18 bad inputs, before vs after) and probe_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 failed ruff check ciphers/porta_cipher.py -> all checks passed python work/R23-T053/probe_bad_inputs.py -> every bad input now raises a clear error Checklist I have tested my changes locally. I have added or updated tests, if needed. I have updated documentation, if needed. I have followed the project's coding guidelines. I have run the relevant tests and checks. I have addressed previous review feedback, if applicable. 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 in work/R23-T053/PROBE.md.
Open Graph Description: Description ciphers/porta_cipher.py had no input validation: bad keys or text crashed with confusing errors (IndexError, KeyError, AttributeError) and one case (ß as a key) silently gave a wrong re...
X Description: Description ciphers/porta_cipher.py had no input validation: bad keys or text crashed with confusing errors (IndexError, KeyError, AttributeError) and one case (ß as a key) silently gave a wrong re...
Opengraph URL: https://github.com/S-AI-Projects/TheAlgorithms-Python/pull/63
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0bf09c51-9119-cfca-d1f7-4be6d53bc77e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C98A:3CDA3E:1072EC:170A1C:6AFDF11C |
| html-safe-nonce | 0a279a0a694391f0e4b6e2367d0f8e5cee8fee1b6d3868819151ca4c37a6e556 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOThBOjNDREEzRToxMDcyRUM6MTcwQTFDOjZBRkRGMTFDIiwidmlzaXRvcl9pZCI6IjU0ODIzMjU2Njg3Njc5NTE2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9a6c2e0966a205e14ef26edef2ae7085dc0ac1b628bc210eefc8fa1ded3d1176 |
| hovercard-subject-tag | pull_request:5253986240 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/S-AI-Projects/TheAlgorithms-Python/pull/63/files |
| twitter:image | https://avatars.githubusercontent.com/u/260575160?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/260575160?s=400&v=4 |
| og:image:alt | Description ciphers/porta_cipher.py had no input validation: bad keys or text crashed with confusing errors (IndexError, KeyError, AttributeError) and one case (ß as a key) silently gave a wrong re... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd812ec581ecac95855f5ec917ef9827506c39a9da1443f43ddb4179a46471eb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/S-AI-Projects/TheAlgorithms-Python git https://github.com/S-AI-Projects/TheAlgorithms-Python.git |
| octolytics-dimension-user_id | 351892385 |
| octolytics-dimension-user_login | S-AI-Projects |
| octolytics-dimension-repository_id | 1444141022 |
| octolytics-dimension-repository_nwo | S-AI-Projects/TheAlgorithms-Python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 63476337 |
| octolytics-dimension-repository_parent_nwo | TheAlgorithms/Python |
| octolytics-dimension-repository_network_root_id | 63476337 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32ac708bac264dafdc28e10ff49b4d137f0c34a7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width