Struct PubKey

Source
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

Source

pub fn encrypt_message(&self, msg: &str) -> Option<BigInt>

encrypt message to ciphertext

Source

pub fn encrypt(&self, m: &BigInt) -> Option<BigInt>

ecrypt integer message to ciphertext Encrypt: additive group A -> additive group B

Source§

impl PubKey

Source

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

Source

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

Source

pub fn add_two_plain_text( &self, plain1: &BigInt, plain2: &BigInt, ) -> Option<BigInt>

m1 + m2

Source

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

Source

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.

Source

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

Source

pub fn mult_two_plain_text( &self, plain1: &BigInt, plain2: &BigInt, ) -> Option<BigInt>

m1 * m2

Source

pub fn div_two_plain_text( &self, plain1: &BigInt, plain2: &BigInt, ) -> Option<BigInt>

m1 / m2

Trait Implementations§

Source§

impl Clone for PubKey

Source§

fn clone(&self) -> PubKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PubKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PubKey

Source§

fn default() -> PubKey

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for PubKey

§

impl RefUnwindSafe for PubKey

§

impl Send for PubKey

§

impl Sync for PubKey

§

impl Unpin for PubKey

§

impl UnwindSafe for PubKey

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.