Graphical Interface (GUI) encryption system that implements a custom block cipher algorithm based on a Substitution-Permutation Network (SPN). It is specifically designed to secure package tracking codes in legacy logistics systems, using purely string manipulations and bitwise operations without external lists or dynamic arrays.
The block_cipher.py program allows encrypting tracking codes to ensure their
integrity. It operates on a restricted alphanumeric alphabet (A-Z, 0-9) and
enforces strict 20-character blocks padding or truncating as necessary. The
algorithm relies heavily on mathematical foundations, enforcing Shannon's
confusion and diffusion principles through custom chaining mechanisms.
The general architecture of the cipher is defined as:
- The input block evaluates characters in an N=36 alphabet (A-Z, 0-9).
- It is strictly adapted to guarantee a maximum size of 20 characters.
- Rules: Rejects accents, spaces, and special characters (like 'ñ').
- Padding/Truncation: If the message is less than 20 characters, smart padding with the letter
Xis applied. If it exceeds the limit, the string is truncated.
-
Master Key (
$K_0$ ): Generated dynamically and deterministically from the input block's characters using purely logical bitwise operations (<<andXOR). -
Round Subkeys (
$K_r$ ): Derived from the original$K_0$ to feed each of the 32 rounds. It uses 16-bit rotation techniques mapped against the Golden Constant (0x9E37) to avoid repetition cycles.
Implements Shannon's Confusion principle.
- Suppresses linear relationships by altering each character in GF(2) field arithmetic (Modulo N).
- Highlights a custom carry chain mechanism: the transformation generated at position
iacts as an additive residue that strongly affects the subsequent positionj > iin that same round.
Implements Shannon's Diffusion principle.
- Applies a fixed global permutation:
$\pi(i) = (7i + 3) \mod 20$ . - The strength of this transposition is mathematically verified by proving it is a perfect bijection (
$\gcd(7, 20) = 1$ ).
According to the mathematical review, the following considerations validate the security and experimental robustness of the cipher:
- Confusion: Actively achieved in the
substitute()function. It uses non-linear modular addition statically coupled with XOR, interacting with 6-bit extracts of the variable subkey. - Diffusion: Achieved by aggressively combining global transposition (
transpose()) with the carry chain mechanism. After completing 32 iterations, modifying a single bit in the input randomly perturbs all characters in the ciphertext.
The application can experimentally demonstrate the effectiveness of scaling to
- R = 1: Low/poor diffusion. Bit tracking only reaches later positions without global interconnection.
- R = 4 to 8: The Permutation+Carry combination achieves ~50% to 80% coverage. The avalanche effect is rapidly compounding.
- R = 16: The exact moment where diffusion reaches complete asymptotic stabilization.
- R = 32 (Operation Default): Employs a conservative 2x multiplier over the base saturation index to rigorously compensate for any weaknesses escaping the defined S-Box symmetry.
-
Differential (Biham & Shamir, 1990): Propagated differences in differential blocks (
$\Delta P$ ) disperse chaotically due to non-linear modular pseudo-random additions. After 32 rounds, carrying a residual bias of$1/36$ , the probability of tracing a coherent path drops mathematically to$p \approx 10^{-50}$ . -
Linear (Matsui, 1993): Linear approximations lack structural traction thanks to Matsui's Piling-Up Lemma. Concatenated logical dependencies expose biases so small (
$10^{-40}$ ) that they are effectively nullified by the dynamic subkey's rotational shift.
- Python 3.6 or higher
tkinter(Native Python library for the GUI)- No external dependencies — standard library only (
pipinstalls not required) - Multi-platform (Windows, macOS, Linux)
To launch the graphical interface application, open your terminal (PowerShell, CMD, or Bash) in the project directory and run:
python block_cipher.pyA minimalist and intuitive interface deploying the exact controls required for research and defense testing:
| Action / Button | Description |
|---|---|
| Message Field | Text input for the logistics tracking code to be encrypted (e.g. PKG2024ABCDEF1234). |
| Cifrar y Reporte | Compiles the iterative process, printing intermediate byte block states at rounds 1, 8, and 32(FINAL). For each step, it records the exact round input, chained substitution result, and diffuse transposition output. |
| Reporte Completo (32 Rondas) | Generates an exhaustive trace, revealing the internal block transformations across every single one of the 32 implemented rounds, fully mapping the input vs. output lifecycle. |
| Analizar Difusión | Runs a strict avalanche test by intentionally altering a single bit in the input message to verify cipher resilience using its original |
| Análisis por Rondas | Progressively evaluates the probabilistic behavior of diffusions across different iteration counts, proving the percentage evolution at R=(1, 4, 8, 16, 32). |
| Limpiar Consola | Clears previous logs and static tabulations from the output window environment. |