JavaScript icon indicating copy to clipboard operation
JavaScript copied to clipboard

Enhancements to Caesar Cipher Implementation - CaesarCipher.js

Open AlexTodorov11 opened this issue 1 year ago • 3 comments

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:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [x] All new JavaScript files are placed inside an existing directory.
  • [x] 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
  • [x] All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • [x] If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

AlexTodorov11 avatar Oct 08 '24 20:10 AlexTodorov11

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 :warning:
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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 08 '24 20:10 codecov-commenter

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

AlexTodorov11 avatar Oct 08 '24 21:10 AlexTodorov11

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.

appgurueu avatar Oct 08 '24 23:10 appgurueu