add pow_mod for DHM-Exchange

This commit is contained in:
none
2023-06-01 10:45:28 +02:00
parent 8ac1a1f31e
commit 5e0dcf1b13
7 changed files with 295 additions and 95 deletions
+14
View File
@@ -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