autoinstall + feistel0 module python
This commit is contained in:
parent
ad7cdd48b1
commit
462ee87ac4
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "plexcryptool"
|
name = "plexcryptool"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -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
|
|
@ -8,6 +8,8 @@
|
||||||
/// License: MIT
|
/// License: MIT
|
||||||
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
/// Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
|
||||||
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
const SBOX: [u8; 0x10] = [0x4, 3, 9, 0xa, 0xb, 2, 0xe, 1, 0xd, 0xc, 8, 6, 7, 5, 0, 0xf];
|
const SBOX: [u8; 0x10] = [0x4, 3, 9, 0xa, 0xb, 2, 0xe, 1, 0xd, 0xc, 8, 6, 7, 5, 0, 0xf];
|
||||||
const ROUNDS: u8 = 3;
|
const ROUNDS: u8 = 3;
|
||||||
|
|
||||||
|
@ -20,6 +22,7 @@ fn test_inner() {
|
||||||
assert!(inner(0x9876, 0xfedc, false) == 0x93c5);
|
assert!(inner(0x9876, 0xfedc, false) == 0x93c5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
|
pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
|
||||||
// cut into u8 blocks
|
// cut into u8 blocks
|
||||||
let mut blocks: [u8; 4] = [
|
let mut blocks: [u8; 4] = [
|
||||||
|
@ -85,6 +88,7 @@ pub fn inner(input: u16, key: u16, verbose: bool) -> u16 {
|
||||||
return result ^ key
|
return result ^ key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
/// Boilerplate KSA, returns the same given values everytime.
|
/// Boilerplate KSA, returns the same given values everytime.
|
||||||
pub fn key_scheduler(_key: u32) -> Vec<u16> {
|
pub fn key_scheduler(_key: u32) -> Vec<u16> {
|
||||||
return vec![0xdead, 0xc0ff, 0xee5a]
|
return vec![0xdead, 0xc0ff, 0xee5a]
|
||||||
|
@ -96,6 +100,7 @@ fn test_encrypt() {
|
||||||
assert_eq!(encrypt(0x12345678, vec![0x1aa2, 0x2bb3, 0x3cc4], true), 0x4313e07a);
|
assert_eq!(encrypt(0x12345678, vec![0x1aa2, 0x2bb3, 0x3cc4], true), 0x4313e07a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
/// encrypt a block
|
/// encrypt a block
|
||||||
pub fn encrypt(plaintext: u32, keys: Vec<u16>, verbose: bool) -> u32 {
|
pub fn encrypt(plaintext: u32, keys: Vec<u16>, verbose: bool) -> u32 {
|
||||||
assert_eq!(keys.len(), ROUNDS as usize);
|
assert_eq!(keys.len(), ROUNDS as usize);
|
||||||
|
@ -133,6 +138,7 @@ fn test_decrypt() {
|
||||||
assert_eq!(plaintext, deciphertext);
|
assert_eq!(plaintext, deciphertext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
/// decrypt a given plaintext with a given key vec
|
/// decrypt a given plaintext with a given key vec
|
||||||
pub fn decrypt(ciphertext: u32, mut keys: Vec<u16>, verbose: bool) -> u32 {
|
pub fn decrypt(ciphertext: u32, mut keys: Vec<u16>, verbose: bool) -> u32 {
|
||||||
assert_eq!(keys.len(), ROUNDS as usize);
|
assert_eq!(keys.len(), ROUNDS as usize);
|
||||||
|
@ -175,6 +181,7 @@ pub fn decrypt(ciphertext: u32, mut keys: Vec<u16>, verbose: bool) -> u32 {
|
||||||
return plaintext;
|
return plaintext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
/// returns the value of the sbox for any input
|
/// returns the value of the sbox for any input
|
||||||
///
|
///
|
||||||
/// max index is 0xf
|
/// max index is 0xf
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -22,6 +22,7 @@ use pyo3::prelude::*;
|
||||||
|
|
||||||
mod binary;
|
mod binary;
|
||||||
mod math;
|
mod math;
|
||||||
|
mod algo;
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
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(())
|
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.
|
/// A Python module implemented in Rust.
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {
|
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
|
|
Loading…
Reference in New Issue