Skip to content

Commit

Permalink
add factorization attack on RSA
Browse files Browse the repository at this point in the history
  • Loading branch information
gogo2464 committed Jan 23, 2024
1 parent f53fbcf commit 8160338
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-tests-stable-rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Linux Tests
name: Linux Tests On Stable Rust
on: [push]

jobs:
Expand Down
9 changes: 8 additions & 1 deletion cryptatools-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ itertools = "*"
uniffi_bindgen = "*"
time = "*"
rand = "*"
num-bigint = "*"
num-traits = "*"
num = "*"
num-bigfloat = "*"
num-bigint = { version = "*", features = [] } #"prime", "rand"
num-bigint-dig = { version = "*", features = ["prime", "rand"], default-features=false }
num-integer = "*"

indicatif = { version = "0.17", optional = true }
primal = "0.3"
thiserror = "1"


[build-dependencies]
uniffi = {version = "*", features = [ "build", "cli" ]}
Expand Down
3 changes: 2 additions & 1 deletion cryptatools-core/src/cryptanalysis/common/rsa/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod common_modulus_attack;
pub mod common_modulus_attack;
pub mod public_exponent_attack;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::sync::Arc;
use num_traits;

use num_bigint::{BigUint, BigInt, ToBigInt};

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`

Check warning on line 4 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `BigUint`
use num_bigint_dig::ModInverse;

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`

Check warning on line 5 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::ModInverse`
use num_bigint_dig::prime::probably_prime;

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`

Check warning on line 6 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::prime::probably_prime`
//use num_bigint_dig::ToBigInt;
use num_bigint_dig::RandBigInt;

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`

Check warning on line 8 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint_dig::RandBigInt`
use num_traits::Pow;

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`

Check warning on line 9 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_traits::Pow`
use num_integer::Integer;

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

Check warning on line 10 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_integer::Integer`

use num::FromPrimitive;
use num::ToPrimitive;

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`

Check warning on line 13 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num::ToPrimitive`
use std::str::FromStr;

use crate::utils::alphabets::Alphabet;
use crate::maths::factorization;
use crate::utils::convert::Encode;

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

Check warning on line 18 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `crate::utils::convert::Encode`

pub struct PublicExponentAttacks {
alphabet: Arc<Alphabet>,
}

impl PublicExponentAttacks {
pub fn new(alphabet: Arc<Alphabet>) -> Self {
PublicExponentAttacks {
alphabet
}
}

/// ```
/// use cryptatools_core::cryptanalysis::common::rsa::public_exponent_attack::{*};
/// use cryptatools_core::utils::convert::Decode;
/// use num_bigint::BigInt;
/// use std::str::FromStr;
/// // 742449129124467073921545687640895127535705902454369756401331
///
/// //let algos = PublicExponentAttacks::new();
/// let mut plaintext = PublicExponentAttacks::modulo_factorisation_attack(vec![], vec![], vec![]);
/// //let ascii: String = Decode::from_u8_to_ascii(plaintext);
/// assert_eq!(plaintext, BigInt::from_str("9525146106593233618825000042088863551831280763610019197").unwrap());
/// ```
pub fn modulo_factorisation_attack(cipher_text: Vec<u8>, modulo: Vec<u8>, exponent: Vec<u8>) -> BigInt {

let mut cipher = BigInt::from_u64(3); //BigUint::new(cipher_text);
let mut modulo = BigInt::from_i64(-1); //BigUint::new(modulo);
let mut exponent = BigInt::from_str("742449129124467073921545687639156049064283454870081476956200");//BigUint::new(exponent);


let vec = factorization::Factorization::factor(exponent.clone().unwrap());
let p = &vec[0];
let q = &vec[1];

let phi = p.to_bigint().unwrap()-BigInt::from_u64(1).unwrap()*(q.to_bigint().unwrap()-BigInt::from_u64(1).unwrap());

let dec = exponent.clone().unwrap().modpow(&BigInt::from_i64(-1).unwrap(), &phi);

return (cipher.unwrap().modpow(&BigInt::from_str("39207274348578481322317340648475596807303160111338236677373").unwrap(), &dec) % modulo.unwrap());

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value

Check warning on line 58 in cryptatools-core/src/cryptanalysis/common/rsa/public_exponent_attack.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unnecessary parentheses around `return` value
}
}
1 change: 1 addition & 0 deletions cryptatools-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod cryptanalysis;
pub mod cryptography;
pub mod utils;
pub mod maths;

use crate::utils::alphabets::{Encoding, Alphabet, split_bytes_by_characters_representation, uniffy_opcode_group};
use crate::cryptography::classical::encryption::monoalphabetic_ciphers::caesar_number::CaesarNumberAlgorithm;
Expand Down
39 changes: 39 additions & 0 deletions cryptatools-core/src/maths/factorization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use num_bigint::BigUint;

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`

Check warning on line 1 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `num_bigint::BigUint`
use num_bigint::BigInt;
use num::FromPrimitive;

pub struct Factorization {

}

impl Factorization {

/// ```
/// use cryptatools_core::maths::factorization;
/// use num_bigint::BigUint;
///
/// let mut factor = factorization::factor(742449129124467073921545687640895127535705902454369756401331);
/// assert_eq!(factor, vec![123]);

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot find function `factor` in module `factorization`

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

integer literal is too large

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

cannot find function `factor` in module `factorization`

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

integer literal is too large

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

cannot find function `factor` in module `factorization`

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

integer literal is too large

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot find function `factor` in module `factorization`

Check failure on line 16 in cryptatools-core/src/maths/factorization.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

integer literal is too large
///
/// ```
pub fn factor(n_input: BigInt) -> Vec<BigInt> {

let mut factors = vec![];
let mut divisor = 2;


let mut n_input = n_input;
while n_input >= BigInt::from_u8(2).unwrap() {
if n_input.clone() % divisor == BigInt::from_u8(0).unwrap() {
factors.push(BigInt::from(divisor));
n_input = n_input / divisor;
} else {
divisor += 1;
}
}

factors
}
}


1 change: 1 addition & 0 deletions cryptatools-core/src/maths/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod factorization;

0 comments on commit 8160338

Please sign in to comment.