mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
最適化
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@ -7,4 +7,7 @@
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
**/*.rs.bk
|
||||
flamegraph.svg
|
||||
perf.data
|
||||
perf.data.old
|
@ -78,8 +78,7 @@ impl Sub for FiniteFieldElement {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
let rhs = FiniteFieldElement::new(-rhs.value, rhs.p);
|
||||
self + rhs
|
||||
Self::new(self.value - rhs.value, rhs.p)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use bigdecimal::{BigDecimal, FromPrimitive, Zero, One};
|
||||
use bigdecimal::{BigDecimal, FromPrimitive, Zero, One, ToPrimitive};
|
||||
|
||||
pub fn ext_gcd(a: BigDecimal, b: BigDecimal) -> (BigDecimal, BigDecimal, BigDecimal) {
|
||||
let mut a = a;
|
||||
@ -50,11 +50,10 @@ pub fn pow(a: BigDecimal, b: BigDecimal) -> BigDecimal {
|
||||
}
|
||||
|
||||
pub fn down(a: BigDecimal) -> BigDecimal {
|
||||
return a.clone() - a % BigDecimal::one();
|
||||
return a.clone() - BigDecimal::from_u128(a.to_u128().unwrap()).unwrap();
|
||||
}
|
||||
|
||||
pub fn floor(a: BigDecimal) -> BigDecimal {
|
||||
|
||||
let m = a.clone() % BigDecimal::one();
|
||||
|
||||
if a > BigDecimal::zero() {
|
||||
|
@ -22,8 +22,10 @@ fn main() {
|
||||
infinity: false
|
||||
};
|
||||
|
||||
println!("{:?}", ec.add(ecp1.clone(), ecp2));
|
||||
/*
|
||||
for x in 0..1000 {
|
||||
println!("{:?}", ec.clone().add(ecp1.clone(), ecp2.clone()));
|
||||
}
|
||||
/*
|
||||
for x in 1..101 {
|
||||
for y in 1..101 {
|
||||
println!("{}, {}: {}", x, y, encrypt::common::math::plusMod(BigDecimal::from_i32(x).unwrap(), BigDecimal::from_i32(y).unwrap()));
|
||||
|
Reference in New Issue
Block a user