added xor
This commit is contained in:
parent
02927ebdc6
commit
f3be0f4661
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
16
src/main.rs
16
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue