MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / mod_exp

Function mod_exp

tests/binary/rsa/src/main.rs:12–25  ·  view source on GitHub ↗

Modular exponentiation: (base^exp) % modulus

(mut base: u64, mut exp: u64, modulus: u64)

Source from the content-addressed store, hash-verified

10
11// Modular exponentiation: (base^exp) % modulus
12fn mod_exp(mut base: u64, mut exp: u64, modulus: u64) -> u64 {
13 let mut result = 1;
14 base %= modulus;
15
16 while exp > 0 {
17 if exp % 2 == 1 {
18 result = (result * base) % modulus;
19 }
20 exp >>= 1;
21 base = (base * base) % modulus;
22 }
23
24 result
25}
26
27// Extended Euclidean Algorithm to find modular inverse
28fn mod_inv(a: i64, m: i64) -> i64 {

Callers 2

encryptFunction · 0.85
decryptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected