Skip to content

Paulami Bhosle — R23-T053: Harden ciphers/porta_cipher.py against bad input #53

Open

Description

@ankushbisht01

Student: Paulami Bhosle

Task: R23-T053 · 3 of 10
Repository: https://github.com/S-AI-Projects/TheAlgorithms-Python
Assigned working branch: student/e26b07f0792

Goal

Find inputs that crash or silently give wrong answers, and make the code raise clear exceptions as CONTRIBUTING.md requires. No raises at all: probe non-letter keys, an empty key, lowercase/uppercase mixes and non-string input.

Steps

  1. Try at least 8 bad inputs (wrong type, empty, negative, None, huge, unusual characters) and record what happens to each.
  2. Decide the correct behaviour for each (raise ValueError/TypeError with a clear message, or handle it).
  3. Implement it and add a doctest for every new error path.
  4. Document the input contract in the docstring.
  5. Make the code change in the repository: ciphers/porta_cipher.py: validation for empty or non-letter keys and non-string input, with doctests. Re-run the automated check and the repo's own tests afterwards.
  6. Prepare the PR: on branch R23-T053, commit the code change plus your work/R23-T053/ evidence, put your findings in the PR description and open the PR against the org fork. For a later upstream PR, create a second branch containing only the code change (no work/ folder).

Done when

☐ PR table of ≥8 bad inputs to generate_table/encrypt/decrypt (empty key, digits in key, mixed case, non-string).
☐ ciphers/porta_cipher.py raises ValueError/TypeError with messages and doctests for each decided-invalid input (it had no raises).
☐ Existing 5 doctests pass (ciphers/porta_cipher.py).

Additional task guidance

Additional curated task guidance

Item:
ciphers/porta_cipher.py (103 lines; 5 doctests)

Task type:
Input validation

Code change (goes into the PR):
ciphers/porta_cipher.py: validation for empty or non-letter keys and non-string input, with doctests.

Automated check:
uv run pytest ciphers/porta_cipher.py

Prerequisites:
Linux/WSL2/Codespaces with uv (https://docs.astral.sh/uv/getting-started/installation/); run uv sync --group=test once – it installs the Python version CI uses (.python-version = 3.15t) and the test dependencies, about 1–2 GB

Upstream PR rules:
Follow CONTRIBUTING.md: type hints on every parameter/return, doctests for valid and erroneous input, snake_case file names, no duplicate of an existing implementation, no hand edits to DIRECTORY.md. CI (pytest with doctests, ruff) must pass – bots close PRs without tests or type hints. Keep work/ (benchmarks, notes, property tests) out of the upstream branch; put results in the PR description.

Source (pinned):
https://github.com/TheAlgorithms/Python/blob/574d100b7181956e9c8384552fd078165e4cc326/ciphers/porta_cipher.py

Change:
No change recorded

PR destination:
Preserved pilot guidance

Submission checklist

  • Complete this task and its checks.
  • Add the required evidence and link your pull request here.
  • Select this S-AI-Projects fork as the PR base repository.
  • Request instructor review.

Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions