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

Added Modular Exponential #650

Merged
merged 7 commits into from
Jan 8, 2024
Merged

Added Modular Exponential #650

merged 7 commits into from
Jan 8, 2024

Conversation

tudor-cretu
Copy link
Contributor

@tudor-cretu tudor-cretu commented Jan 8, 2024

Modular Exponential

Description

gcd_extended

The gcd_extended function implements the Extended Euclidean Algorithm, which is used to find the greatest common divisor (GCD) of two integers, as well as the coefficients of Bézout's identity. This is particularly useful in number theory and cryptography, especially for finding the modular inverse of an integer. Our implementation uses a recursive approach to calculate these values.

mod_inverse

The mod_inverse function utilizes the gcd_extended function to compute the modular multiplicative inverse of an integer b modulo m. The modular inverse is an integer x such that (b * x) % m = 1. This function is essential for operations in modular arithmetic where division is required. The function will panic if the inverse does not exist, which occurs when b and m are not coprime.

modular_exponential

The modular_exponential function performs modular exponentiation which is a type of exponentiation performed over a modulus. It is used to efficiently compute base^power % modulus for large integers. This is a fundamental operation in many cryptographic algorithms. Our function handles both positive and negative exponents, using the mod_inverse function for negative exponents to compute the result.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@tudor-cretu tudor-cretu closed this Jan 8, 2024
@tudor-cretu tudor-cretu reopened this Jan 8, 2024
@tudor-cretu tudor-cretu marked this pull request as ready for review January 8, 2024 11:47
@codecov-commenter
Copy link

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (3a1724d) 94.58% compared to head (edf08df) 94.59%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/math/modular_exponential.rs 98.48% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #650      +/-   ##
==========================================
+ Coverage   94.58%   94.59%   +0.01%     
==========================================
  Files         283      284       +1     
  Lines       22801    22867      +66     
==========================================
+ Hits        21566    21631      +65     
- Misses       1235     1236       +1     

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

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit 61c417d into TheAlgorithms:master Jan 8, 2024
4 checks 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.

3 participants