pub struct PubKey {
pub g: BigInt,
pub n: BigInt,
pub nn: BigInt,
}
Expand description
PubKey – Publick Key
Fields§
§g: BigInt
§n: BigInt
§nn: BigInt
Implementations§
Source§impl PubKey
impl PubKey
Sourcepub fn add_plain_text(
&self,
ciphertext: &BigInt,
msg: &BigInt,
) -> Option<BigInt>
pub fn add_plain_text( &self, ciphertext: &BigInt, msg: &BigInt, ) -> Option<BigInt>
D(E(m1) * E(m2) mod n^2) = m1 + m2 mod n this formula not efficient, cause operation E has more OP steps
=> D(E(m1) * g^m2 mod n^2) = m1 + m2 mod n That is efficient, Simplified steps
D(add_plain_text(E(m1), m2)) = m1 + m2 mod n
returns added msg encrypted result
add_plain_text(&self, ciphertext: &BigInt, msg: &str) -> Option
Sourcepub fn add(&self, ciphertext1: &BigInt, ciphertext2: &BigInt) -> Option<BigInt>
pub fn add(&self, ciphertext1: &BigInt, ciphertext2: &BigInt) -> Option<BigInt>
D(add(E(m1), E(m2))) = m1 + m2 mod n returns added sum of two encrypted data
Sourcepub fn add_two_plain_text(
&self,
plain1: &BigInt,
plain2: &BigInt,
) -> Option<BigInt>
pub fn add_two_plain_text( &self, plain1: &BigInt, plain2: &BigInt, ) -> Option<BigInt>
m1 + m2
Sourcepub fn sub(&self, ciphertext1: &BigInt, ciphertext2: &BigInt) -> Option<BigInt>
pub fn sub(&self, ciphertext1: &BigInt, ciphertext2: &BigInt) -> Option<BigInt>
D(sub(E(m1), E(m2))) = E(m1) - E(m2) mod n if m1 > m2 returns sub result of two encrypted data
Sourcepub fn mult_plain_text(
&self,
ciphertext: &BigInt,
plain_k: &BigInt,
) -> Option<BigInt>
pub fn mult_plain_text( &self, ciphertext: &BigInt, plain_k: &BigInt, ) -> Option<BigInt>
D(E(m1)^m2 mod n^2) = m1m2 mod n => D(E(m2)^m1 mod n^2) = m1m2 mod n = m2m1 mod n => D(E(m)^k mod n^2) = km mod n Dec(mult_plain_text(E(m1), m2)) = m1 * m2 mod n. returns result of multiplication of two ciphertexts D(E(m)^k mod n^2) = k*m mod n Dec(mult_k(E(m1), m2)) = m1 * m2 mod n.
Sourcepub fn div_plain_text(
&self,
ciphertext: &BigInt,
plain_k: &BigInt,
) -> Option<BigInt>
pub fn div_plain_text( &self, ciphertext: &BigInt, plain_k: &BigInt, ) -> Option<BigInt>
D(E(m)^-k mod n^2) = D(E(m)^(inverse k) mod n^2) = m / k mod n Dec(div_plain_text(E(m1), m2)) = m1 / m2 mod n. returns result division of two ciphertext