Implement challenge 33 Diffie-Hellman
This commit is contained in:
12
src/rsa.rs
Normal file
12
src/rsa.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
pub fn expmod(base: u32, exp: u32, m: u32) -> u32 {
|
||||
if exp == 0 {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if exp % 2 == 0 {
|
||||
let s = expmod(base, exp / 2, m);
|
||||
(s * s) % m
|
||||
} else {
|
||||
(expmod(base, exp - 1, m) * base) % m
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user