diff --git a/Cargo.toml b/Cargo.toml
index 8e15f91..c9789ba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "plexcryptool"
-version = "0.1.2"
+version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..ec3b1bf
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+rm target/wheels -rf
+cargo install --path .
+maturin build --release
+pip install target/wheels/plexcryptool*x86_64.whl --force
diff --git a/src/algo/feistel0.rs b/src/algo/feistel0.rs
index aa90f03..a71dd73 100644
--- a/src/algo/feistel0.rs
+++ b/src/algo/feistel0.rs
@@ -8,6 +8,8 @@
/// License: MIT
/// Source:
+use pyo3::prelude::*;
+
const SBOX: [u8; 0x10] = [0x4, 3, 9, 0xa, 0xb, 2, 0xe, 1, 0xd, 0xc, 8, 6, 7, 5, 0, 0xf];
const ROUNDS: u8 = 3;
@@ -20,6 +22,7 @@ fn test_inner() {
assert!(inner(0x9876, 0xfedc, false) == 0x93c5);
}
+#[pyfunction]
pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
// cut into u8 blocks
let mut blocks: [u8; 4] = [
@@ -85,6 +88,7 @@ pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
return result ^ key
}
+#[pyfunction]
/// Boilerplate KSA, returns the same given values everytime.
pub fn key_scheduler(_key: u32) -> Vec {
return vec![0xdead, 0xc0ff, 0xee5a]
@@ -96,6 +100,7 @@ fn test_encrypt() {
assert_eq!(encrypt(0x12345678, vec![0x1aa2, 0x2bb3, 0x3cc4], true), 0x4313e07a);
}
+#[pyfunction]
/// encrypt a block
pub fn encrypt(plaintext: u32, keys: Vec, verbose: bool) -> u32 {
assert_eq!(keys.len(), ROUNDS as usize);
@@ -133,6 +138,7 @@ fn test_decrypt() {
assert_eq!(plaintext, deciphertext);
}
+#[pyfunction]
/// decrypt a given plaintext with a given key vec
pub fn decrypt(ciphertext: u32, mut keys: Vec, verbose: bool) -> u32 {
assert_eq!(keys.len(), ROUNDS as usize);
@@ -175,6 +181,7 @@ pub fn decrypt(ciphertext: u32, mut keys: Vec, verbose: bool) -> u32 {
return plaintext;
}
+#[pyfunction]
/// returns the value of the sbox for any input
///
/// max index is 0xf
diff --git a/src/lib.rs b/src/lib.rs
index e279819..01ba2d0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -22,6 +22,7 @@ use pyo3::prelude::*;
mod binary;
mod math;
+mod algo;
#[pymodule]
fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
@@ -41,6 +42,17 @@ fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
Ok(())
}
+#[pymodule]
+fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
+ let algo_module = PyModule::new(py, "algo")?;
+ algo_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, algo_module)?)?;
+ algo_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, algo_module)?)?;
+ algo_module.add_function(wrap_pyfunction!(algo::feistel0::sbox, algo_module)?)?;
+ algo_module.add_function(wrap_pyfunction!(algo::feistel0::key_scheduler, algo_module)?)?;
+ parent_module.add_submodule(algo_module)?;
+ Ok(())
+}
+
/// A Python module implemented in Rust.
#[pymodule]
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {