Skip to content

Code that calculates the modular multiplicative inverse of a number making use of the Euclidean algorithm.

Notifications You must be signed in to change notification settings

cchhiissoomm/Multiplicative-Inverse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multiplicative-Inverse-Rust

This rust code calculates the modular multiplicative inverse of a number making use of the Euclidean algorithm.

fn mod_inv(a: isize, module: isize) -> isize {

let mut mn = (module, a);
let mut xy = (0, 1);

while mn.1 != 0 {
  xy = (xy.1, xy.0 - (mn.0/mn.1) * xy.1);
  mn = (mn.1, mn.0 % mn.1);
}
//implementation of euclidean algorithm
while xy.0 < 0 {
  xy.0 += module;
}
xy.0
}
//driver code
fn main() {
  //function call
println!("{}", mod_inv(29, 90)) /*input your interger and modulo respectively*/
}

About

Code that calculates the modular multiplicative inverse of a number making use of the Euclidean algorithm.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages