scripts module and type hinting
This commit is contained in:
parent
a0448a339a
commit
9d37023df4
|
@ -1 +1,2 @@
|
||||||
from .plexcryptool import *
|
from .plexcryptool import *
|
||||||
|
from . import scripts as scripts
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
"""
|
||||||
|
Bindings for the plexcryptool rust library
|
||||||
|
|
||||||
|
plexcryptool.plexcryptool is direct access to the shared library, do not use it.
|
||||||
|
"""
|
||||||
|
from . import binary
|
||||||
|
from . import math
|
||||||
|
from . import algo
|
||||||
|
from . import cplex
|
||||||
|
from . import scripts
|
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
various algorithms implemented
|
||||||
|
"""
|
||||||
|
from . import feistel0 as feistel0
|
|
@ -0,0 +1,59 @@
|
||||||
|
"""
|
||||||
|
# basic implementation of a feistel network
|
||||||
|
|
||||||
|
This module implements a feistel network according to an exercise at DHBW Mannheim.
|
||||||
|
For demonstration purposes only, do not use this in a secure environment.
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
def inner(input: int, key: int, verbose: bool) -> int:
|
||||||
|
"""
|
||||||
|
the inner function of the feistel network
|
||||||
|
|
||||||
|
takes input, scrambles it by using two s and p boxes,
|
||||||
|
then xors with the key.
|
||||||
|
|
||||||
|
:param input unsigned 16 bit int
|
||||||
|
:param key unsigned 16 bit int
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def encrypt(plaintext: int, keys: list[int], verbose: bool) -> int:
|
||||||
|
"""
|
||||||
|
encrypt using the feistel0 network
|
||||||
|
|
||||||
|
performes some rounds of the feistelnetwork to encrypt the input.
|
||||||
|
This will only encrypt a single block.
|
||||||
|
|
||||||
|
DO NOT USE THIS FOR ACTUAL ENCRYPTION!
|
||||||
|
|
||||||
|
:param plaintext unsigned 32 bit int
|
||||||
|
:param keys vec of the round keys, usually 3 diffrent ones.
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def decrypt(ciphertext: int, keys: list[int], verbose: bool) -> int:
|
||||||
|
"""
|
||||||
|
decrypt using the feistel0 network
|
||||||
|
|
||||||
|
performs encryption backwards more or less
|
||||||
|
|
||||||
|
DO NOT USE THIS FOR ACTUAL ENCRYPTION!
|
||||||
|
|
||||||
|
:param ciphertext unsigned 32 bit int
|
||||||
|
:param keys vec of the round keys, usually 3 diffrent ones.
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def sbox(index: int) -> int:
|
||||||
|
"""
|
||||||
|
returns the value of the sbox at index.
|
||||||
|
|
||||||
|
:param index range 0 - 15
|
||||||
|
"""
|
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
various common functionalities used by many modules
|
||||||
|
"""
|
||||||
|
from . import printing as printing
|
|
@ -0,0 +1,28 @@
|
||||||
|
"""
|
||||||
|
common functionality for printing
|
||||||
|
|
||||||
|
Implements code that might be used by many other modules
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def version():
|
||||||
|
"""
|
||||||
|
prints the plexcryptool version
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def about():
|
||||||
|
"""
|
||||||
|
prints the about section
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def seperator():
|
||||||
|
"""
|
||||||
|
prints a separator line
|
||||||
|
"""
|
||||||
|
...
|
|
@ -1,10 +0,0 @@
|
||||||
"""
|
|
||||||
Some basic math functionalities
|
|
||||||
"""
|
|
||||||
def modular_exponentiation(base: int, exp: int, field: int) -> int:
|
|
||||||
"""
|
|
||||||
calculates base^exp in the gallois given gallois field
|
|
||||||
|
|
||||||
Uses iterative squaring to be able to calculate large exponents aswell.
|
|
||||||
"""
|
|
||||||
...
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""
|
||||||
|
# math module
|
||||||
|
|
||||||
|
Funcionality for math things. Contains tedious algorithms like binary exponentiation.
|
||||||
|
"""
|
||||||
|
from . import modexp as modexp
|
||||||
|
from . import modred as modred
|
||||||
|
from . import pm1 as pm1
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
"""
|
||||||
|
modular exponentiaton
|
||||||
|
|
||||||
|
Implements fast exponentiation with applied modulo. Usefull for calculations in a gallois
|
||||||
|
field.
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def modular_exponentiation(
|
||||||
|
base: int,
|
||||||
|
orig_exp: int,
|
||||||
|
field: int,
|
||||||
|
verbose: bool
|
||||||
|
) -> int:
|
||||||
|
"""
|
||||||
|
perform modular exponentiation
|
||||||
|
|
||||||
|
:param base the base of the exponentiation
|
||||||
|
:param orig_exp the exponent of the base
|
||||||
|
:param field the number that describes the gallois field (should be prime)
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
|
@ -0,0 +1,23 @@
|
||||||
|
"""
|
||||||
|
modular reduction
|
||||||
|
|
||||||
|
Implements automatic modular reduction in a field specified by a given relation.
|
||||||
|
|
||||||
|
Basically, any binary number can be written as a polynomial. This polynomial can be reduced by
|
||||||
|
the relation that defines a field. In that field. This is what we call modular reduction.
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def modred(poly: int, relation: int, verbose: bool) -> int:
|
||||||
|
"""
|
||||||
|
perform modular reduction
|
||||||
|
|
||||||
|
:param poly the polynomial as int
|
||||||
|
:param relation the relation as int
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
|
@ -0,0 +1,29 @@
|
||||||
|
"""
|
||||||
|
P minus 1 method
|
||||||
|
|
||||||
|
Determine the prime factors of a number with the p minus 1 method.
|
||||||
|
Effecient for numbers with low ranged prime factors.
|
||||||
|
|
||||||
|
___
|
||||||
|
@Author: Christoph J. Scherr <software@cscherr.de>
|
||||||
|
@License: MIT
|
||||||
|
@Source: <https://git.cscherr.de/PlexSheep/plexcryptool/>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def p_minus_one(n: int, max_prime: int, verbose: bool) -> list[int]:
|
||||||
|
"""
|
||||||
|
p minus 1 prime number test
|
||||||
|
|
||||||
|
:param n u128 number to check
|
||||||
|
:param max_prime the highest prime power to use
|
||||||
|
:param verbose print steps
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
def alt_gcd(a: int, b: int) -> int:
|
||||||
|
"""
|
||||||
|
find greatest common divisor
|
||||||
|
|
||||||
|
this is a primitive extended euclidic algorithm.
|
||||||
|
"""
|
||||||
|
...
|
|
@ -2,4 +2,5 @@
|
||||||
Bindings for the plexcryptool rust library
|
Bindings for the plexcryptool rust library
|
||||||
|
|
||||||
plexcryptool.plexcryptool is direct access to the shared library, do not use it.
|
plexcryptool.plexcryptool is direct access to the shared library, do not use it.
|
||||||
|
(you should not see this specific version of this text)
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""
|
||||||
|
various scripts
|
||||||
|
|
||||||
|
these are coded in python and can currently not be called from the executable.
|
||||||
|
"""
|
||||||
|
from . import authur1 as authur1
|
||||||
|
from . import basic_decrypt as basic_decrypt
|
||||||
|
from . import md5_analyzer as md5_analyzer
|
||||||
|
from . import trash_hash as trash_hash
|
|
@ -1,6 +1,6 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
/// common functionality
|
/// common functionality for printing
|
||||||
///
|
///
|
||||||
/// Implements code that might be used by many other modules
|
/// Implements code that might be used by many other modules
|
||||||
///
|
///
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
use crate::cplex::printing::seperator;
|
use crate::cplex::printing::seperator;
|
||||||
|
|
||||||
|
use pyo3::{prelude::*, exceptions::PyException};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_modred() {
|
fn test_modred() {
|
||||||
let rel: u64 = 0x1053;
|
let rel: u64 = 0x1053;
|
||||||
|
@ -19,6 +21,9 @@ fn test_modred() {
|
||||||
assert_eq!(modred(pol0, rel, false).unwrap(), 0x21e);
|
assert_eq!(modred(pol0, rel, false).unwrap(), 0x21e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// modular reduction of a polynomial with a given relation
|
||||||
|
///
|
||||||
|
/// (the function uses the integer representations)
|
||||||
pub fn modred(mut poly: u64, relation: u64, verbose: bool) -> Result<u64, String> {
|
pub fn modred(mut poly: u64, relation: u64, verbose: bool) -> Result<u64, String> {
|
||||||
|
|
||||||
let mut diffrence: u32;
|
let mut diffrence: u32;
|
||||||
|
@ -44,3 +49,18 @@ pub fn modred(mut poly: u64, relation: u64, verbose: bool) -> Result<u64, String
|
||||||
}
|
}
|
||||||
return Ok(poly);
|
return Ok(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
#[pyo3(name="mordred")]
|
||||||
|
/// python wrapper for modred
|
||||||
|
pub fn py_modred(poly: u64, relation: u64, verbose: bool) -> PyResult<u64> {
|
||||||
|
let res = modred(poly, relation, verbose);
|
||||||
|
match res {
|
||||||
|
Ok(n) => {
|
||||||
|
return Ok(n);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(PyException::new_err(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue