added xor

This commit is contained in:
Christoph J. Scherr 2023-05-10 13:03:01 +02:00
parent 02927ebdc6
commit f3be0f4661
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
3 changed files with 22 additions and 0 deletions

View File

@ -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
}

View File

@ -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(())
}

View File

@ -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)
}
}
}