From f3be0f4661807b2e2cebb9f9131f63823c8df76f Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 10 May 2023 13:03:01 +0200 Subject: [PATCH] added xor --- src/binary/mod.rs | 5 +++++ src/lib.rs | 1 + src/main.rs | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/binary/mod.rs b/src/binary/mod.rs index 20916df..f348714 100644 --- a/src/binary/mod.rs +++ b/src/binary/mod.rs @@ -21,3 +21,8 @@ pub fn rotl32 (value: u32, count: u32) -> u32 { pub fn rotr32 (value: u32, count: u32) -> u32 { value.rotate_right(count as u32) } + +#[pyfunction] +pub fn xor(a: u128, b: u128) -> u128 { + a | b +} diff --git a/src/lib.rs b/src/lib.rs index 63bb029..e279819 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,7 @@ fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> let binary_module = PyModule::new(py, "binary")?; binary_module.add_function(wrap_pyfunction!(binary::rotl32, binary_module)?)?; binary_module.add_function(wrap_pyfunction!(binary::rotr32, binary_module)?)?; + binary_module.add_function(wrap_pyfunction!(binary::xor, binary_module)?)?; parent_module.add_submodule(binary_module)?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 21d7e1b..d64bd9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,7 @@ enum BinaryActions { /// bit rotation/circular shifting (only 32bit) #[command(name="rotate")] Rotate(RotateArgs), + Xor(XorArgs) } #[derive(Args, Clone, Debug, PartialEq, Eq)] @@ -91,6 +92,12 @@ struct RotateArgs { shift_width: u32, } +#[derive(Args, Clone, Debug, PartialEq, Eq)] +struct XorArgs { + a: u128, + b: u128, +} + /*************************************************************************************************/ /// main function of plexcryptool. /// @@ -131,6 +138,15 @@ pub fn main() { else { println!("result is {}", result) } + }, + BinaryActions::Xor(bin_xor_args) => { + let result: u128 = binary::xor(bin_xor_args.a, bin_xor_args.b); + if args.machine { + println!("{}", result) + } + else { + println!("result is {}", result) + } } }