add pow_mod for DHM-Exchange
This commit is contained in:
@@ -4,6 +4,8 @@ use serde::{Serialize, Deserialize};
|
||||
use sha2::{Digest,Sha512};
|
||||
use regex::Regex;
|
||||
use crc32fast;
|
||||
use rand::{rngs::StdRng, RngCore, SeedableRng};
|
||||
use num_bigint::BigUint;
|
||||
|
||||
mod big_array;
|
||||
use big_array::BigArray;
|
||||
@@ -36,6 +38,18 @@ struct StrPacket {
|
||||
payload: [u8; MAX_PAYLOAD_U]
|
||||
}
|
||||
|
||||
fn pow_mod(num: BigUint, pow: BigUint, modulo: BigUint) -> BigUint {
|
||||
let mut result = BigUint::from(1u8);
|
||||
let one = BigUint::from(1u8);
|
||||
let mut i = BigUint::from(0u8);
|
||||
while i < pow {
|
||||
result = (result * &num) % &modulo;
|
||||
i += &one;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let port = "1337";
|
||||
let timeout = 100; //ms
|
||||
|
||||
Reference in New Issue
Block a user