mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
add PPE substract multiply
This commit is contained in:
@ -9,7 +9,8 @@ fn main() {
|
|||||||
println("d: " + d)
|
println("d: " + d)
|
||||||
let e = encrypt(24)
|
let e = encrypt(24)
|
||||||
println("e: " + e)
|
println("e: " + e)
|
||||||
let r = a + b + c + d + e
|
let f = encrypt(15)
|
||||||
|
let r = a + b + c + d + e - f
|
||||||
println("r: " + decrypt(r));
|
println("r: " + decrypt(r));
|
||||||
println(decrypt(r) - 15)
|
println(decrypt(r * 2))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
ops::{Add, Sub},
|
ops::{Add, Mul, Sub},
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
@ -70,6 +70,29 @@ impl Sub for EncryptedEllipticCurvePoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Mul<U512> for EncryptedEllipticCurvePoint {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, rhs: U512) -> Self::Output {
|
||||||
|
let mut tmp = self;
|
||||||
|
let mut point: Option<EncryptedEllipticCurvePoint> = None;
|
||||||
|
let mut n = rhs;
|
||||||
|
while n > U512::zero() {
|
||||||
|
if n & U512::one() == U512::one() {
|
||||||
|
if let Some(s_point) = point {
|
||||||
|
point = Some(s_point + tmp);
|
||||||
|
} else {
|
||||||
|
point = Some(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n = n >> 1;
|
||||||
|
tmp = tmp + tmp;
|
||||||
|
}
|
||||||
|
point.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Encryption {
|
impl Encryption {
|
||||||
pub fn ec_point_to_plain(&self, point: EllipticCurvePoint) -> U512 {
|
pub fn ec_point_to_plain(&self, point: EllipticCurvePoint) -> U512 {
|
||||||
match point {
|
match point {
|
||||||
|
@ -423,21 +423,48 @@ impl GPSL {
|
|||||||
},
|
},
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
NodeKind::MUL => match GPSL::extract_number(lhs) {
|
NodeKind::MUL => match lhs.clone() {
|
||||||
|
Variable::Number { value: lhs } => match rhs {
|
||||||
|
Variable::Number { value: rhs } => {
|
||||||
|
Ok(Some(Variable::Number { value: lhs * rhs }))
|
||||||
|
}
|
||||||
|
_ => Err("Cannot multiply non-number to number.".to_string()),
|
||||||
|
},
|
||||||
|
Variable::PureEncrypted { value: lhs } => match rhs {
|
||||||
|
Variable::Number { value: rhs } => {
|
||||||
|
Ok(Some(Variable::PureEncrypted {
|
||||||
|
value: lhs * U512::from(rhs),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
Variable::U512 { value: rhs } => {
|
||||||
|
Ok(Some(Variable::PureEncrypted { value: lhs * rhs }))
|
||||||
|
}
|
||||||
|
_ => Err("Cannot multiply non-number to ppe.".to_string()),
|
||||||
|
},
|
||||||
|
_ => Err("Cannot multiply non-number.".to_string()),
|
||||||
|
},
|
||||||
|
/*match GPSL::extract_number(lhs) {
|
||||||
Ok(lhs) => match GPSL::extract_number(rhs) {
|
Ok(lhs) => match GPSL::extract_number(rhs) {
|
||||||
Ok(rhs) => Ok(Some(Variable::Number { value: lhs * rhs })),
|
Ok(rhs) => Ok(Some(Variable::Number { value: lhs * rhs })),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},*/
|
||||||
NodeKind::SUB => match GPSL::extract_number(lhs) {
|
NodeKind::SUB => match lhs.clone() {
|
||||||
Ok(lhs) => match GPSL::extract_number(rhs) {
|
Variable::Number { value: lhs } => match rhs {
|
||||||
Ok(rhs) => Ok(Some(Variable::Number { value: lhs - rhs })),
|
Variable::Number { value: rhs } => {
|
||||||
Err(err) => Err(err),
|
Ok(Some(Variable::Number { value: lhs - rhs }))
|
||||||
|
}
|
||||||
|
_ => Err("Cannot subtract non-number from number.".to_string()),
|
||||||
},
|
},
|
||||||
Err(err) => Err(err),
|
Variable::PureEncrypted { value: lhs } => match rhs {
|
||||||
|
Variable::PureEncrypted { value: rhs } => {
|
||||||
|
Ok(Some(Variable::PureEncrypted { value: lhs - rhs }))
|
||||||
|
}
|
||||||
|
_ => Err("Cannot subtract non-ppe from ppe.".to_string()),
|
||||||
|
},
|
||||||
|
_ => Err("Cannot subtract non-number.".to_string()),
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeKind::EQ => {
|
NodeKind::EQ => {
|
||||||
if lhs == rhs {
|
if lhs == rhs {
|
||||||
Ok(Some(Variable::Number { value: 1 }))
|
Ok(Some(Variable::Number { value: 1 }))
|
||||||
|
Reference in New Issue
Block a user