Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CaeserCipherDecrypt.py #19

Merged
merged 1 commit into from
Oct 28, 2024
Merged

Create CaeserCipherDecrypt.py #19

merged 1 commit into from
Oct 28, 2024

Conversation

dhavalpandey
Copy link
Contributor

@dhavalpandey dhavalpandey commented Oct 27, 2024

Decrypting algorithm that decrypts an encoded string generated by a ceaser cipher. Requires encoded string and key as input.

Summary by Sourcery

New Features:

  • Implement a function to decrypt strings encoded with a Caesar cipher, accepting an encoded string and a key as input.

Decrypting algorithm that decrypts an encoded string generated by a ceaser cipher. Requires encoded string and key as input.
Copy link
Contributor

sourcery-ai bot commented Oct 27, 2024

Reviewer's Guide by Sourcery

This PR implements a Caesar cipher decryption algorithm in Python. The implementation handles both uppercase and lowercase letters while preserving non-alphabetic characters. The program takes user input for the encoded string and shift key, then outputs the decoded result.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implementation of Caesar cipher decryption function
  • Created main decryption function that processes each character individually
  • Added separate handling for uppercase and lowercase letters using ASCII arithmetic
  • Preserved non-alphabetic characters in the output
  • Implemented modulo 26 operation to handle alphabet wrapping
  • Added user input collection for encoded text and shift key
  • Included result output formatting
Python/CaeserCipherDecrypt.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dhavalpandey - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider separating the cipher logic from I/O operations by moving the input/output code to a separate main() function. This would improve reusability and testability.
  • Add error handling for the key input to handle non-integer inputs gracefully. Currently the program will crash if non-numeric input is provided.
  • Replace magic numbers (65, 97) with named constants (ord('A'), ord('a')) to improve code readability and maintainability.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

result = ""
for char in text:
if char.isupper():
result += chr((ord(char) - key - 65) % 26 + 65)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Replace magic numbers with more readable constants

Consider using ord('A') instead of 65 and ord('a') instead of 97 to make the code more readable and maintainable.

Suggested change
result += chr((ord(char) - key - 65) % 26 + 65)
result += chr((ord(char) - key - ord('A')) % 26 + ord('A'))

@x0lg0n x0lg0n merged commit d338902 into x0lg0n:main Oct 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants