fancy module system
This commit is contained in:
parent
e247c4c12f
commit
0e6fe6eda7
|
@ -1,4 +1,12 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
/// binary functions
|
||||||
|
///
|
||||||
|
/// This module contains some functions that manipulate binary values.
|
||||||
|
///
|
||||||
|
/// Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
/// License: MIT
|
||||||
|
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pythons bit operations are trash, so I made a rust lib for that.
|
* Pythons bit operations are trash, so I made a rust lib for that.
|
||||||
*/
|
*/
|
18
src/lib.rs
18
src/lib.rs
|
@ -1,7 +1,21 @@
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
#![warn(clippy::missing_docs_in_private_items)]
|
||||||
|
//! # various tools for use in cryptology contexts
|
||||||
|
//!
|
||||||
|
//! This is a mixed rust/python library that also offers an executable.
|
||||||
|
//! The intended usage is the solving of tasks for cryptology and maybe math, in the context of a
|
||||||
|
//! university degree. I wrote this for cryptology at DHBW Mannheim.
|
||||||
|
//!
|
||||||
|
//! ___
|
||||||
|
//! Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
//!
|
||||||
|
//! License: MIT
|
||||||
|
//!
|
||||||
|
//! Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
mod binary;
|
mod binary;
|
||||||
mod modular_exponentiation;
|
mod math;
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
|
@ -15,7 +29,7 @@ fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()>
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
let math_module = PyModule::new(py, "math")?;
|
let math_module = PyModule::new(py, "math")?;
|
||||||
math_module.add_function(wrap_pyfunction!(modular_exponentiation::py_modular_exponentiation, math_module)?)?;
|
math_module.add_function(wrap_pyfunction!(math::modexp::py_modular_exponentiation, math_module)?)?;
|
||||||
parent_module.add_submodule(math_module)?;
|
parent_module.add_submodule(math_module)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -1,10 +1,22 @@
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
#![warn(clippy::missing_docs_in_private_items)]
|
||||||
|
//!
|
||||||
|
//! This is a mixed rust/python library that also offers an executable.
|
||||||
|
//! The intended usage is the solving of tasks for cryptology and maybe math, in the context of a
|
||||||
|
//! # various tools for use in cryptology contexts
|
||||||
|
//! university degree. I wrote this for cryptology at DHBW Mannheim.
|
||||||
|
//!
|
||||||
|
//! ___
|
||||||
|
//! Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
//!
|
||||||
|
//! License: MIT
|
||||||
|
//!
|
||||||
|
//! Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
mod binary;
|
mod binary;
|
||||||
mod modular_exponentiation;
|
mod math;
|
||||||
|
|
||||||
use std::{str::FromStr, fmt::Debug};
|
use std::{str::FromStr, fmt::Debug};
|
||||||
|
|
||||||
use modular_exponentiation::modular_exponentiation;
|
|
||||||
|
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
use num_bigint;
|
use num_bigint;
|
||||||
/*************************************************************************************************/
|
/*************************************************************************************************/
|
||||||
|
@ -74,6 +86,10 @@ struct RotateArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************************************/
|
/*************************************************************************************************/
|
||||||
|
/// main function of plexcryptool.
|
||||||
|
///
|
||||||
|
/// This function is the entrypoint of the binary. It parses Commandline options and calls the
|
||||||
|
/// internal functions with the corresponding values, then shows the results to the user.
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
match args.command {
|
match args.command {
|
||||||
|
@ -83,7 +99,7 @@ pub fn main() {
|
||||||
let b = num_bigint::BigInt::from_str(&mod_exp_args.base.as_str()).expect("could not make bigint");
|
let b = num_bigint::BigInt::from_str(&mod_exp_args.base.as_str()).expect("could not make bigint");
|
||||||
let e = num_bigint::BigInt::from_str(&mod_exp_args.exp.as_str()).expect("could not make bigint");
|
let e = num_bigint::BigInt::from_str(&mod_exp_args.exp.as_str()).expect("could not make bigint");
|
||||||
let f = num_bigint::BigInt::from_str(&mod_exp_args.field.as_str()).expect("could not make bigint");
|
let f = num_bigint::BigInt::from_str(&mod_exp_args.field.as_str()).expect("could not make bigint");
|
||||||
let result = modular_exponentiation(b.clone(), e, f, args.verbose);
|
let result = math::modexp::modular_exponentiation(b.clone(), e, f, args.verbose);
|
||||||
if args.machine {
|
if args.machine {
|
||||||
println!("{}", result)
|
println!("{}", result)
|
||||||
}
|
}
|
||||||
|
@ -113,10 +129,5 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback, this should ideally not execute
|
|
||||||
_ => {
|
|
||||||
eprintln!("Command not implemented.\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/// # math module
|
||||||
|
///
|
||||||
|
/// funcionality for math things. Contains tedious algorithms like binary exponentiation.
|
||||||
|
pub mod modexp;
|
|
@ -1,6 +1,14 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
/// modular exponentiaton
|
||||||
|
///
|
||||||
|
/// Implements fast exponentiation with applied modulo. Usefull for calculations in a gallois
|
||||||
|
/// field.
|
||||||
|
///
|
||||||
|
/// Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
/// License: MIT
|
||||||
|
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
|
||||||
use num_bigint::{BigInt, BigUint};
|
use num_bigint::BigInt;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use pyo3::exceptions::PyValueError;
|
use pyo3::exceptions::PyValueError;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
Loading…
Reference in New Issue