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

Enhancements to Caesar Cipher Implementation - CaesarCipher.js #1721

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AlexTodorov11
Copy link

@AlexTodorov11 AlexTodorov11 commented Oct 8, 2024

Open in Gitpod know more

Describe your change:

Improves the existing Caesar Cipher implementation to make it more robust, future-proof, and flexible. Key improvements include handling edge cases, optimizing performance, and adding support for custom alphabets. These changes enhance both the functionality and maintainability of the code.

  • The function now accepts an optional alphabet parameter, allowing encryption with custom alphabets (e.g., different languages).
  • Rotations are now optimized to handle values greater than the alphabet length by using rotation % alphabetLength.
  • Non-alphabetic characters (numbers, symbols, etc.) are explicitly left unchanged in the encrypted output.
  • The function throws appropriate errors for invalid input types (e.g., non-string, negative rotations) and gracefully handles empty strings.
  • The function maintains the case of letters, ensuring that uppercase letters remain uppercase after encryption.
  • The cipher map is now generated only once per function call, reducing overhead for large strings.

Additional Changes:

  • Improved code readability with clearer logic and added comments for better maintainability.
  • Added input validation to ensure rotation is a non-negative integer.

No Issue related to PR at the time of creation. Comment or contact if wrongful.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Improves the existing Caesar Cipher implementation to make it more robust, future-proof, and flexible. Key improvements include handling edge cases, optimizing performance, and adding support for custom alphabets. These changes enhance both the functionality and maintainability of the code.
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.65%. Comparing base (18da83a) to head (ab9ba90).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
Ciphers/CaesarCipher.js 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1721      +/-   ##
==========================================
- Coverage   84.65%   84.65%   -0.01%     
==========================================
  Files         378      378              
  Lines       19744    19757      +13     
  Branches     2951     2951              
==========================================
+ Hits        16715    16726      +11     
- Misses       3029     3031       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AlexTodorov11
Copy link
Author

Can someone please assist or advise how I can fix the "Continuous Integration / Code style and tests (pull_request)" test?

@appgurueu
Copy link
Collaborator

Can someone please assist or advise how I can fix the "Continuous Integration / Code style and tests (pull_request)" test?

You need to run prettier to fix the style issues. The CI output says that.

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.

3 participants