Skip to content

Commit

Permalink
codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-H11 committed Apr 6, 2024
1 parent a295b45 commit 374fc77
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ mod tests {

#[test]
fn test_blocks_which_need_padding() {
let m = vec![BigInt::from_str("141003468806831291709021908155318047884").unwrap(),
BigInt::from_str("92324319300612212196142259885788683544").unwrap(),
BigInt::from_str("56230357520496568317607899257571094993").unwrap(),
BigInt::from_str("2205566786287507744272597928496806444").unwrap(),
BigInt::from_str("97117935781375881927035254884658165460").unwrap()
let m = vec![
BigInt::from_str("141003468806831291709021908155318047884").unwrap(),
BigInt::from_str("92324319300612212196142259885788683544").unwrap(),
BigInt::from_str("56230357520496568317607899257571094993").unwrap(),
BigInt::from_str("2205566786287507744272597928496806444").unwrap(),
BigInt::from_str("97117935781375881927035254884658165460").unwrap(),
];
let key = DecimalUnicodeConversionSchemeKey {
radix: 55296,
Expand All @@ -234,7 +235,6 @@ mod tests {

let ciphertext = FromDecimalBlockScheme::encrypt(&m, &key);


let plaintext = FromDecimalBlockScheme::decrypt(&ciphertext, &key);

assert_eq!(m, plaintext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ impl AsymmetricEncryptor<MenezesVanstoneStringScheme> for MenezesVanstoneStringS
big_int_vec.push(ciphertext.second.clone());
}

let conversion_post_key = DecimalUnicodeConversionSchemeKey { radix, block_size: block_size + 1 };
let conversion_post_key = DecimalUnicodeConversionSchemeKey {
radix,
block_size: block_size + 1,
};
let ciphertext_string = FromDecimalBlockScheme::encrypt(&big_int_vec, &conversion_post_key);

// Die genutzten Punkte akkumulieren
Expand Down Expand Up @@ -145,7 +148,8 @@ impl AsymmetricDecryptor<MenezesVanstoneStringScheme> for MenezesVanstoneStringS

// Die Zahlen in eine Liste von MenezesVanstoneCiphertext mappen
let mut ciphertext_list: Vec<MenezesVanstoneCiphertext> = Vec::new();
for mut i in (0..big_int_vec.len()).step_by(2) { // TODO Aufhübschen
for mut i in (0..big_int_vec.len()).step_by(2) {
// TODO Aufhübschen
let first = big_int_vec[i].clone();
let second = if i + 1 < big_int_vec.len() {
big_int_vec[i + 1].clone()
Expand Down
39 changes: 24 additions & 15 deletions src/math_core/complex_number.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cmp::Ordering;
use bigdecimal::{BigDecimal, Signed, Zero};
use std::ops::{Add, Div, Mul, Sub};
use bigdecimal::num_bigint::ToBigInt;
use bigdecimal::num_traits::Euclid;
use bigdecimal::{BigDecimal, Signed, Zero};
use num::BigInt;
use sha2::digest::typenum::private::IsGreaterOrEqualPrivate;
use std::cmp::Ordering;
use std::ops::{Add, Div, Mul, Sub};

#[derive(Clone, Debug, PartialEq)]
pub struct ComplexNumber {
Expand Down Expand Up @@ -33,15 +33,15 @@ impl ComplexNumber {
self.real.is_negative() && self.imaginary.is_negative()
}

pub fn absolute_value(&self) -> Option<BigDecimal>{
pub fn absolute_value(&self) -> Option<BigDecimal> {
BigDecimal::from(&self.real * &self.real + &self.imaginary * &self.imaginary).sqrt()
}

pub fn is_greater_than(&self, other: &Self) -> bool{
pub fn is_greater_than(&self, other: &Self) -> bool {
self.absolute_value() > other.absolute_value()
}

pub fn is_less_than(&self, other: &Self) -> bool{
pub fn is_less_than(&self, other: &Self) -> bool {
self.absolute_value() < other.absolute_value()
}

Expand All @@ -50,19 +50,28 @@ impl ComplexNumber {
}

pub fn div_round(&self, rhs: &Self) -> Self {
Self{
real: (BigDecimal::from(&self.real * &rhs.real + &self.imaginary * &rhs.imaginary) /
BigDecimal::from(&rhs.real * &rhs.real + &rhs.imaginary * &rhs.imaginary)).round(0).to_bigint().unwrap(),
imaginary: (BigDecimal::from(&self.imaginary * &rhs.real - &self.real * &rhs.imaginary) /
BigDecimal::from(&rhs.real * &rhs.real + &rhs.imaginary * &rhs.imaginary)).round(0).to_bigint().unwrap()
Self {
real: (BigDecimal::from(&self.real * &rhs.real + &self.imaginary * &rhs.imaginary)
/ BigDecimal::from(&rhs.real * &rhs.real + &rhs.imaginary * &rhs.imaginary))
.round(0)
.to_bigint()
.unwrap(),
imaginary: (BigDecimal::from(
&self.imaginary * &rhs.real - &self.real * &rhs.imaginary,
) / BigDecimal::from(
&rhs.real * &rhs.real + &rhs.imaginary * &rhs.imaginary,
))
.round(0)
.to_bigint()
.unwrap(),
}
}
}

pub fn complex_euclidean_algorithm(a: ComplexNumber, b: ComplexNumber) -> ComplexNumber {
let mut g:ComplexNumber;
let mut g_prev:ComplexNumber;
if a.is_greater_than(&b){
let mut g: ComplexNumber;
let mut g_prev: ComplexNumber;
if a.is_greater_than(&b) {
g = b;
g_prev = a;
} else {
Expand Down Expand Up @@ -175,8 +184,8 @@ impl Div for &ComplexNumber {

#[cfg(test)]
mod tests {
use num::Integer;
use super::*;
use num::Integer;

#[test]
fn complex_test() {
Expand Down

0 comments on commit 374fc77

Please sign in to comment.