Research and educational use only. No warranty is provided regarding cryptographic security.
PMTC is not a replacement for AES-256, ChaCha20, XChaCha20, or any standardized cipher.
The Pure Manifold Trajectory Cipher (PMTC) is an experimental cryptographic research project exploring whether a nonlinear dynamical system — built from prime-field arithmetic, manifold-inspired high-dimensional state space, ARX transformations (Addition-Rotation-XOR), and cross-coupled state trajectories — can generate cryptographically useful keystreams.
Unlike conventional stream ciphers, PMTC treats encryption as the evolution of a high-dimensional nonlinear state manifold whose trajectory is continuously perturbed by ciphertext feedback.
This project was developed experimentally — including some AI-assisted or "vibe-coded" iteration — while exploring cryptography, software architecture, and the interaction between abstract mathematics and computation. It is presented openly as a learning and research project rather than as a claim of professional cryptographic validation.
This repository continues an earlier PMTC prototype of mine. It was initialized as a new repository after substantial changes to the cipher specification, testing framework, and research direction.
It is computationally heavy, so it may not have practical use cases. A possible future direction is to explore whether ideas from this symmetric-key experiment can inform public-key research.
- Explore manifold-inspired nonlinear state evolution
- Utilize prime-field arithmetic as a source of algebraic complexity
- Introduce cross-coupled state trajectories
- Investigate whether complex deterministic dynamics can produce cryptographically useful behavior
- Probe behavior under statistical, differential, and prediction-style tests
Genesis Seed
↓
PBKDF2-HMAC-SHA256 Key Derivation (600,000 iterations)
↓
Prime Field Manifold Initialization (secondary PBKDF2, 10,000 iterations + 16 warm-up rounds)
↓
Nonlinear State Evolution
↓
┌─────────────────────────────────────────────┐
│ Per Full Manifold Round: │
│ Prime Field Round │
│ × 6: ARX Quarter Round │
│ Cross-Coupling Round │
│ Permutation Round │
└─────────────────────────────────────────────┘
↓
Keystream Extraction (2 manifold rounds + finalizer per byte)
↓
XOR Encryption + Ciphertext Feedback (2 manifold rounds per byte)
↓
HMAC-SHA256 Authentication
The system maintains two interacting state spaces, totaling 12 state variables plus a counter (13 values total).
Four variables, each evolving inside its own large prime field:
| Variable | Prime Modulus |
|---|---|
x |
2147483647 |
y |
4294967291 |
z |
9223372036854775783 |
w |
18446744073709551557 |
MOD_X = 2147483647
MOD_Y = 4294967291
MOD_Z = 9223372036854775783
MOD_W = 18446744073709551557Each state is initialized from the seed material and sanitized to be non-zero (zero is replaced with 1) before any rounds run.
Eight 64-bit integer variables: a, b, c, d, e, f, g, h.
These provide fast diffusion and mixing across the full state space.
The Genesis Seed is the master secret from which all keys are derived.
9dc598e1de13406673664556e228a7bd89ca341818d1773f7c9442e4ef4e0061
It is a 64-character hex string (32 random bytes) generated via secrets.token_hex(32). The implementation rejects malformed or short seeds. It is never transmitted. Without it, decryption is infeasible under the assumptions of the experiment.
The Genesis Seed is processed with PBKDF2-HMAC-SHA256:
| Parameter | Value |
|---|---|
| Input | Normalized Genesis Seed (ASCII hex) |
| Salt | Random 16-byte salt |
| Iterations | 600,000 |
| Output | 64 bytes |
The 64-byte output is split into:
- Bytes 0–31 → 32-byte encryption key
- Bytes 32–63 → 32-byte authentication key
Inside PureManifoldCipher.__init__, a second PBKDF2-HMAC-SHA256 pass is run:
| Parameter | Value |
|---|---|
| Input | Encryption key |
| Salt | Random 32-byte IV |
| Iterations | 10,000 |
| Output | 64 bytes |
This 64-byte seed material initializes all 12 state variables (x, y, z, w, a, b, c, d, e, f, g, h) and the counter. After initialization, 16 warm-up rounds are executed with payload byte 0xA5 to mix the state before any keystream is produced.
The primary source of nonlinear behavior. Each call updates all four prime-field variables using:
- Modular exponentiation:
pow(x, 3, MOD_X),pow(y, 5, MOD_Y), etc. - Modular inverse: native modular inversion via
pow(v, -1, prime). If an inverse target is0 mod p, the implementation substitutes1as a deterministic fallback, so that transition is a defined rule rather than a true inverse. - Cross-state interaction: ARX states feed into prime-field updates
Conceptually:
x(n+1) = f(x, y, z, w, a, counter, payload)
The modular inverse introduces strong nonlinearity while remaining deterministic:
a × a⁻¹ ≡ 1 (mod p)
Six ARX quarter rounds execute per full manifold round. Each round applies Addition, Rotation, and XOR to all eight ARX variables, with prime field states injected directly:
a = (a + b + x) & MASK64
d ^= a
d = rotl64(d, 32)
c = (c + d + y) & MASK64
b ^= c
b = rotl64(b, 24)
# ... continued across all 8 variablesARX constructions provide fast mixing and are commonly used as diffusion layers. Their presence here does not by itself prove resistance to linear attacks.
Executed once per ARX iteration, this layer directly ties the prime-field states into the ARX variables and vice versa:
a ^= ((x << 33) | y | m) & MASK64
b = (b + rotl64(z & MASK64, 19) + m) & MASK64
g ^= rotr64((x * 0x9E3779B97F4A7C15) & MASK64, 31)This is intended to make independent analysis of either subsystem harder by tying the update paths together.
Executed once per ARX iteration. Variables are swapped and then mixed with rotations:
a, b, c, d = c, d, a, b
e, f, g, h = g, h, e, f
a ^= rotl64(e, 7)
b = (b + rotr64(f, 11)) & MASK64
# ...This increases diffusion and reduces the chance that local structure survives across rounds.
One complete round consists of:
- One prime field round
- Six iterations of:
- ARX quarter round
- Cross-coupling round
- Permutation round
- Counter increment
- State sanitization
For each keystream byte, get_keystream_byte() executes two full manifold rounds before extracting:
self._full_manifold_round(0x00)
self._full_manifold_round(0x5A)
return self._extract_byte_from_manifold()The extractor combines the 12 state variables plus the counter with rotations and XOR, then applies a 3-step integer finalizer (similar to MurmurHash3/xxHash) to collapse the 64-bit combined value to a single output byte:
out = (a ^ rotr64(b,7) ^ rotl64(c,13) ^ rotr64(d,29)
^ e ^ rotl64(f,37) ^ rotr64(g,43) ^ h
^ x ^ y ^ z ^ w ^ counter) & MASK64
out ^= out >> 33
out = (out * 0xff51afd7ed558ccd) & MASK64
out ^= out >> 33
out = (out * 0xc4ceb9fe1a85ec53) & MASK64
out ^= out >> 33
return out & 0xFFFor each plaintext byte:
ciphertext_byte = plaintext_byte XOR keystream_byte
After each byte is encrypted, mutate_manifold(ciphertext_byte) runs two additional full manifold rounds, injecting the ciphertext byte back into the state:
self._full_manifold_round(payload_byte)
self._full_manifold_round(payload_byte ^ 0xA5)This creates ciphertext feedback: future state evolution depends on all previous ciphertext output.
Decryption is structurally identical — the same ciphertext byte is used to mutate the manifold in both directions, keeping the state synchronized:
plaintext_byte = ciphertext_byte XOR keystream_byte
mutate_manifold(ciphertext_byte) # same call as encryption
The encrypted output is a Base64-encoded JSON package containing:
| Field | Description |
|---|---|
header |
Cipher metadata (version, algorithm identifiers) |
salt |
Base64-encoded 16-byte random salt |
iv |
Base64-encoded 32-byte random IV |
ciphertext |
Base64-encoded encrypted bytes |
tag |
Base64-encoded HMAC-SHA256 authentication tag |
The token format version used by main_2.py is 6.
HMAC-SHA256 is computed over the concatenation of:
header_bytes || salt || iv || ciphertext
using the 32-byte authentication key derived in Stage 1. This detects tampering, modification attempts, and forged ciphertexts when the Genesis Seed is unknown. Authentication is verified before any decryption occurs.
Create the project-local Python environment once after cloning:
python3 -m venv .venvThe shared PyCharm run configuration named PMTC v6 uses
.venv/bin/python automatically.
.venv/bin/python main_2.py[1] Enter existing Genesis Seed
[2] Generate new random Genesis Seed
[>] Select mode 1 or 2: 2
[+] Genesis Seed: 9dc598e1de13406673664556e228a7bd89ca341818d1773f7c9442e4ef4e0061
[>] Enter a message to encrypt: Hello World
[+] ENCRYPTED TOKEN:
eyJ...
Save both the Genesis Seed and the Encrypted Token. Both are required for decryption.
python decrypt.pyProvide the Genesis Seed and the Encrypted Token. Decryption succeeds only if:
- The HMAC tag is valid
- The Genesis Seed is correct
- The ciphertext has not been modified
The framework uses main_2.py as its sole cipher implementation:
# In security test scripts or decrypt.py
TARGET_CIPHER_MODULE = "main_2"The decryptor and standalone security scripts are configured to use this module.
# Dependency-free regression and security-characterization suite
python -m unittest discover -s tests -v
# Structural avalanche, randomized prefix uniqueness, and tamper verification
python security_tests_attack.py
# N-gram prediction, position matrices, and distinguisher tests
python state_recovery_attack_test.py
# Basic and advanced smoke/security checks
python security_tests_basic.py
python security_tests_adv.py
# Ablation diagnostics
python security_test_ablation.pyThe tests/ suite is intended for repeatable development checks. It includes:
- A fixed v6 known-answer vector covering encryption and HMAC
- Prime-modulus validation
- Authenticated-component mutation and truncated-tag rejection
- Explicit characterization of key/IV reuse leakage
- State-bit, absorbed-byte, and reduced-round differentia
0 comments
log in to comment.